[wp-trac] [WordPress Trac] #44579: get_option() is type aware now (returns Integers as Integers)

WordPress Trac noreply at wordpress.org
Fri Jul 13 14:32:43 UTC 2018


#44579: get_option() is type aware now (returns Integers as Integers)
--------------------------------+------------------------------
 Reporter:  gdespoulain         |       Owner:  (none)
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:  trunk
 Severity:  minor               |  Resolution:
 Keywords:                      |     Focuses:  docs
--------------------------------+------------------------------

Comment (by boonebgorges):

 Hi @gdespoulain - Welcome to Trac, and thanks for the ticket!

 The bit of documentation you cite here was added in [36234]. You can read
 the backstory in #31820 and #22192, but briefly: `get_option()` and
 similar functions return all values as strings *except when pulled from
 memory on the same pageload as when `update_option()` is called*. So:

 {{{
 update_option( 'foo', 1 );
 var_dump( get_option( 'foo' ) );
 // int

 update_option( 'foo', 1 );
 // refresh page
 var_dump( get_option( 'foo' ) );
 // string
 }}}

 You may also see the same behavior between pageloads if you're running a
 persistent cache (Memcache, Redis, etc) depending on the nature of the
 cache. Can you confirm?

 This being said, this bit of documentation could probably be improved.
 Something like "Note that scalar values may be returned as strings when
 retrieved from the database" might be a more accurate wording.

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


More information about the wp-trac mailing list