From f375b68447d392ca7c189ebfadb6b908931d3812 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 15 May 2023 10:26:54 +0000 Subject: [PATCH] General: Remove a few `is_object()` checks followed by `instanceof` operator. This is a minor performance enhancement: * If an object is passed, the call to `is_object()` will be redundant. * If a non-object is passed, the `instanceof` operator (a variant of `is_a()`) will first [https://github.com/php/php-src/blob/f42992f/Zend/zend_builtin_functions.c#L630-L631 check if it is an object] before doing any further processing. Therefore, no additional processing cycles should be wasted in both cases. Follow-up to [6779], [48798], [48905], [49194], [55748]. Props Presskopp, costdev. Fixes #58309. git-svn-id: https://develop.svn.wordpress.org/trunk@55757 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-pclzip.php | 8 ++++---- src/wp-includes/media.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/includes/class-pclzip.php b/src/wp-admin/includes/class-pclzip.php index b1b39e2dfe..3f26dee2e4 100644 --- a/src/wp-admin/includes/class-pclzip.php +++ b/src/wp-admin/includes/class-pclzip.php @@ -1170,8 +1170,8 @@ // ----- Reset the error handler $this->privErrorReset(); - // ----- Look if the $p_archive is a PclZip object - if (is_object($p_archive) && $p_archive instanceof pclzip) + // ----- Look if the $p_archive is an instantiated PclZip object + if ($p_archive instanceof pclzip) { // ----- Duplicate the archive @@ -1234,8 +1234,8 @@ return(0); } - // ----- Look if the $p_archive_to_add is a PclZip object - if (is_object($p_archive_to_add) && $p_archive_to_add instanceof pclzip) + // ----- Look if the $p_archive_to_add is an instantiated PclZip object + if ($p_archive_to_add instanceof pclzip) { // ----- Merge the archive diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 281e896fa0..0d22ada14e 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -3748,8 +3748,8 @@ function get_taxonomies_for_attachments( $output = 'names' ) { * Determines whether the value is an acceptable type for GD image functions. * * In PHP 8.0, the GD extension uses GdImage objects for its data structures. - * This function checks if the passed value is either a resource of type `gd` - * or a GdImage object instance. Any other type will return false. + * This function checks if the passed value is either a GdImage object instance + * or a resource of type `gd`. Any other type will return false. * * @since 5.6.0 * @@ -3758,8 +3758,8 @@ function get_taxonomies_for_attachments( $output = 'names' ) { * false otherwise. */ function is_gd_image( $image ) { - if ( is_resource( $image ) && 'gd' === get_resource_type( $image ) - || is_object( $image ) && $image instanceof GdImage + if ( $image instanceof GdImage + || is_resource( $image ) && 'gd' === get_resource_type( $image ) ) { return true; }