[wp-trac] [WordPress Trac] #55942: Add a "type" field to the meta and options tables

WordPress Trac noreply at wordpress.org
Sat Mar 11 01:37:14 UTC 2023


#55942: Add a "type" field to the meta and options tables
-------------------------------------------------+-------------------------
 Reporter:  azaozz                               |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Database                             |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  testing                                        |  performance
-------------------------------------------------+-------------------------

Comment (by azaozz):

 Replying to [comment:25 barry.hughes]:
 > What do we think about the (optional) ability to specify the underlying
 type, on read as well as upon write?

 Thinking the simpler/more straightforward solution would be to set the
 type automatically depending on the data. For example doing
 `update_option( 'my_option', 123 )` would insert the `123` in the DB and
 set the type to integer. Then doing `get_option( 'my_option' )` would
 return the DB value unchanged, i.e. a string `'123'` for back-compat, and
 doing `get_option( 'my_option', $default_value, 'strict' )` would return
 int `123`.

 > that would close off scenarios where third party code replaces an option
 with a value requiring PHP serialization...

 Serialization is (just a) DB storage requirement/method. It should happen
 automatically when needed. When the changes here are implemented all new
 and updated options and meta values will automatically have data types. If
 the data type is array or object, the DB output will be unserialized and
 returned. As data types will be added automatically on saving to the DB,
 there will be no errors (unless someone "hacks" the valued directly in the
 database).

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


More information about the wp-trac mailing list