From 051cae396efa88f3755013fac7aa62f1b06959dc Mon Sep 17 00:00:00 2001 From: liaisontw Date: Thu, 26 Mar 2026 17:29:48 +0800 Subject: [PATCH 1/2] Cache: Ensure wp_using_ext_object_cache() returns a boolean --- src/wp-includes/load.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 27c58b57dd671..ebbbd8c17e1bc 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -808,15 +808,20 @@ function wp_set_wpdb_vars() { * @return bool The current 'using' setting. */ function wp_using_ext_object_cache( $using = null ) { - global $_wp_using_ext_object_cache; + global $_wp_using_ext_object_cache; - $current_using = $_wp_using_ext_object_cache; + // Save the current state to return later. + $current_using = $_wp_using_ext_object_cache; - if ( null !== $using ) { - $_wp_using_ext_object_cache = $using; - } + if ( null !== $using ) { + $_wp_using_ext_object_cache = (bool) $using; + } - return $current_using; + /** + * Ensure the returned value is always a boolean. + * If the global is uninitialized, it could be null, which violates the type signature. + */ + return (bool) $current_using; } /** From 427727284f1386e2faf74683c9781a30cfc6c336 Mon Sep 17 00:00:00 2001 From: liaisontw Date: Mon, 20 Apr 2026 12:43:40 +0800 Subject: [PATCH 2/2] Load: Ensure wp_using_ext_object_cache() always returns a boolean. --- src/wp-includes/load.php | 23 ++++++------- .../tests/load/wpUsingExtObjectCache.php | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 tests/phpunit/tests/load/wpUsingExtObjectCache.php diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index ebbbd8c17e1bc..3dc215ea9ee01 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -808,20 +808,21 @@ function wp_set_wpdb_vars() { * @return bool The current 'using' setting. */ function wp_using_ext_object_cache( $using = null ) { - global $_wp_using_ext_object_cache; + global $_wp_using_ext_object_cache; - // Save the current state to return later. - $current_using = $_wp_using_ext_object_cache; + // Save the current state to return later. + $current_using = $_wp_using_ext_object_cache; - if ( null !== $using ) { - $_wp_using_ext_object_cache = (bool) $using; - } + if ( null !== $using ) { + $_wp_using_ext_object_cache = (bool) $using; + } + + if ( null === $_wp_using_ext_object_cache ) { + // If the global is uninitialized, the value would be null, which violates the type signature. + return false; + } - /** - * Ensure the returned value is always a boolean. - * If the global is uninitialized, it could be null, which violates the type signature. - */ - return (bool) $current_using; + return (bool) $current_using; } /** diff --git a/tests/phpunit/tests/load/wpUsingExtObjectCache.php b/tests/phpunit/tests/load/wpUsingExtObjectCache.php new file mode 100644 index 0000000000000..8f99893b02ea0 --- /dev/null +++ b/tests/phpunit/tests/load/wpUsingExtObjectCache.php @@ -0,0 +1,32 @@ +orig_using_ext_cache = $_wp_using_ext_object_cache; + } + + public function tear_down() { + global $_wp_using_ext_object_cache; + + $_wp_using_ext_object_cache = $this->orig_using_ext_cache; + parent::tear_down(); + } + + public function test_should_always_return_boolean() { + wp_using_ext_object_cache( 1 ); + $this->assertIsBool( wp_using_ext_object_cache() ); + } +}