[wp-trac] [WordPress Trac] #51278: Update return types to reflect the real return types. Remove mixed.

WordPress Trac noreply at wordpress.org
Sun Nov 15 09:48:23 UTC 2020


#51278: Update return types to reflect the real return types. Remove mixed.
-------------------------+-------------------------------------
 Reporter:  ReneHermi    |       Owner:  johnbillion
     Type:  enhancement  |      Status:  reviewing
 Priority:  normal       |   Milestone:  Future Release
Component:  General      |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  docs, coding-standards
-------------------------+-------------------------------------

Comment (by azaozz):

 [49600] is a good addition but there are some "gotchas" there which are
 worth documenting imho. Most importantly that options are always saved as
 strings in the DB. Example:

 {{{
 add_option( 'my_test_option__false', false );
 add_option( 'my_test_option__true', true );
 add_option( 'my_test_option__0', 0 );
 add_option( 'my_test_option__1', 1 );
 add_option( 'my_test_option__str_0', '0' );
 add_option( 'my_test_option__str_1', '1' );
 }}}

 Then doing `var_dump( get_option( 'my_test_option...' ) );` will output:

 {{{
 string(0) ""
 string(1) "1"
 string(1) "0"
 string(1) "1"
 string(1) "0"
 string(1) "1"
 }}}

 This is especially important (big back-compat "gotcha") for PHP 8.0 as
 string to number comparison was changed there, see:
 https://core.trac.wordpress.org/changeset/48960.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51278#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list