[wp-trac] [WordPress Trac] #64950: wp_using_ext_object_cache can return null, causing type failures, potential fatals
WordPress Trac
noreply at wordpress.org
Thu Mar 26 09:59:34 UTC 2026
#64950: wp_using_ext_object_cache can return null, causing type failures, potential
fatals
--------------------------+------------------------------
Reporter: ronalfy | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Cache API | Version: 3.7
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+------------------------------
Comment (by liaison):
I have submitted a PR that addresses the return type inconsistency by
casting the value to (bool). This ensures compliance with the documented
return type and prevents null leaks in early-loading scenarios.
I’ve verified the fix with an isolated test script, and it correctly
returns false instead of null when the global state is uninitialized.
test script: debug-cache-bug.php
{{{#!php
<?php
/**
* Test script for Ticket #64950
* Purpose: Verify that wp_using_ext_object_cache() returns bool instead
of null.
* * This script isolates the Cache API environment to catch the
uninitialized
* global variable state.
*/
// 1. Mock environment paths
define( 'ABSPATH', dirname( __FILE__ ) . '/' );
define( 'WPINC', 'wp-includes' );
// 2. Load only the target file where the function is defined
require_once ABSPATH . WPINC . '/load.php';
echo "=== WordPress Core Ticket #64950 Test ===" . PHP_EOL;
// Test 1: Initial state (Global variable is undefined/uninitialized)
echo "1. Initial call (Global is undefined):" . PHP_EOL;
$initial = wp_using_ext_object_cache();
var_dump( $initial );
if ( is_null( $initial ) ) {
echo "❌ [FAIL] Returned NULL. This violates the @return bool
signature." . PHP_EOL;
} elseif ( is_bool( $initial ) ) {
echo "✅ [PASS] Returned boolean (" . ( $initial ? 'true' : 'false' )
. ")." . PHP_EOL;
}
echo PHP_EOL;
// Test 2: Set new value and check return value (Swap/Toggle pattern)
echo "2. Setting to TRUE (Testing Swap pattern):" . PHP_EOL;
/**
* Expected behavior:
* Returns the current (old) state, then updates the global to the new
value.
*/
$old_val = wp_using_ext_object_cache( true );
echo "Returned (Old) Value: ";
var_dump( $old_val );
echo "Current Global State (Should be true): ";
var_dump( wp_using_ext_object_cache() );
echo "=========================================" . PHP_EOL;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64950#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list