[wp-trac] [WordPress Trac] #20004: Fix NULL and FALSE in WP_Object_Cache and make found/not-found unambiguous.

WordPress Trac wp-trac at lists.automattic.com
Thu Feb 9 22:49:14 UTC 2012


#20004: Fix NULL and FALSE in WP_Object_Cache and make found/not-found unambiguous.
------------------------------------+------------------------------
 Reporter:  andy                    |       Owner:
     Type:  defect (bug)            |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  Cache                   |     Version:
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |
------------------------------------+------------------------------

Comment (by nacin):

 What about `wp_cache_exists( $key, $group )`? No last-resultness or by-ref
 variable necessary. It would function similar to `metadata_exists()` and
 simply return whether the key exists in the group, rather than its actual
 value.

 Also, as long as the reference is declared with the function, and is not
 call-time pass-by-reference, PHP will not issue a notice here. No $found =
 null necessary.

 You can test this as follows:
 {{{
 error_reporting( -1 );
 function test( &$found ) {}
 test( $found );
 var_dump( $found ); // NULL, no notice.
 }}}

 You will, however, end up with a notice the moment you try to ascertain
 $found before it is passed into the function:
 {{{
 error_reporting( -1 );
 function test( &$found ) {}
 var_dump( $found ); // E_NOTICE
 test( $found );
 var_dump( $found ); // NULL, no notice.
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20004#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list