Commit 7dc0d4f3b04 for woocommerce
commit 7dc0d4f3b040b3c31249c28288f33c42b920c81e
Author: Dhrupo <dhrupo@gmail.com>
Date: Fri Nov 6 23:07:47 2026 +0600
Fix PHP 8.6 deprecations in Analytics reports, approved download directories and CallbackUtil (#70743)
* Fix PHP 8.6 deprecations in Analytics reports, approved download directories and CallbackUtil
PHP 8.6 deprecates returning a value from a constructor, is_integer() and spl_object_hash(). GenericQuery::__construct() returned the parent constructor's (void) result, the approved directories editor used is_integer(), and CallbackUtil used spl_object_hash() in its closure fallback.
* Keep spl_object_hash() in the CallbackUtil closure fallback before PHP 8.1
* Remove GenericQuery constructor entries from the PHPStan baseline
---------
Co-authored-by: Mike Jolley <mike.jolley@me.com>
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 6378bb66407..e6f3ca6c80e 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -40827,24 +40827,12 @@ parameters:
count: 1
path: src/Admin/API/Reports/GenericQuery.php
- -
- message: '#^Method Automattic\\WooCommerce\\Admin\\API\\Reports\\GenericQuery\:\:__construct\(\) with return type void returns null but should not return anything\.$#'
- identifier: return.void
- count: 1
- path: src/Admin/API/Reports/GenericQuery.php
-
-
message: '#^PHPDoc tag @extends has invalid value \(WC_Object_Query\:\:_construct\)\: Unexpected token "\:\:", expected ''\<'' at offset 174 on line 6$#'
identifier: phpDoc.parseError
count: 1
path: src/Admin/API/Reports/GenericQuery.php
- -
- message: '#^Result of method WC_Object_Query\:\:__construct\(\) \(void\) is used\.$#'
- identifier: staticMethod.void
- count: 1
- path: src/Admin/API/Reports/GenericQuery.php
-
-
message: '#^Method Automattic\\WooCommerce\\Admin\\API\\Reports\\GenericStatsController\:\:get_items\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
identifier: missingType.generics
diff --git a/plugins/woocommerce/src/Admin/API/Reports/GenericQuery.php b/plugins/woocommerce/src/Admin/API/Reports/GenericQuery.php
index 8b8e4c03e2f..a60a48155ab 100644
--- a/plugins/woocommerce/src/Admin/API/Reports/GenericQuery.php
+++ b/plugins/woocommerce/src/Admin/API/Reports/GenericQuery.php
@@ -47,7 +47,7 @@ class GenericQuery extends \WC_Object_Query {
public function __construct( $args, $name = null ) {
$this->name = $name ?? $this->name;
- return parent::__construct( $args ); // phpcs:ignore Universal.CodeAnalysis.ConstructorDestructorReturn.ReturnValueFound
+ parent::__construct( $args );
}
/**
* Valid fields for Products report.
diff --git a/plugins/woocommerce/src/Internal/ProductDownloads/ApprovedDirectories/Admin/UI.php b/plugins/woocommerce/src/Internal/ProductDownloads/ApprovedDirectories/Admin/UI.php
index af561626d5c..cf0caa99933 100644
--- a/plugins/woocommerce/src/Internal/ProductDownloads/ApprovedDirectories/Admin/UI.php
+++ b/plugins/woocommerce/src/Internal/ProductDownloads/ApprovedDirectories/Admin/UI.php
@@ -206,7 +206,7 @@ class UI {
? $this->register->add_approved_directory( $url, $enabled )
: $this->register->update_approved_directory( $url_id, $url, $enabled );
- if ( is_integer( $upserted ) ) {
+ if ( is_int( $upserted ) ) {
$redirect_url = add_query_arg( 'url', $upserted, $redirect_url );
}
diff --git a/plugins/woocommerce/src/Utilities/CallbackUtil.php b/plugins/woocommerce/src/Utilities/CallbackUtil.php
index 16698f2ae30..96c9dc2c963 100644
--- a/plugins/woocommerce/src/Utilities/CallbackUtil.php
+++ b/plugins/woocommerce/src/Utilities/CallbackUtil.php
@@ -43,7 +43,8 @@ final class CallbackUtil {
try {
return self::get_closure_signature( $callback );
} catch ( \Exception $e ) {
- return 'Closure@' . spl_object_hash( $callback );
+ // spl_object_hash() is deprecated in PHP 8.6; from PHP 8.1 it returns exactly this string.
+ return 'Closure@' . ( PHP_VERSION_ID >= 80100 ? sprintf( '%016x0000000000000000', spl_object_id( $callback ) ) : spl_object_hash( $callback ) );
}
}