[wp-trac] [WordPress Trac] #55942: Add a "value type" parameter to get_option() and get_metadata()

WordPress Trac noreply at wordpress.org
Fri Apr 28 22:38:34 UTC 2023


#55942: Add a "value type" parameter to get_option() and get_metadata()
-------------------------------------------------+-------------------------
 Reporter:  azaozz                               |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  6.3
Component:  Options, Meta APIs                   |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  testing                                        |  performance
-------------------------------------------------+-------------------------

Comment (by knutsp):

 'number' should be treated as union type int|float (PHP 8.0) and pass the
 `is_numeric()` test. Both `register_[setting|meta]()` and typed
 `[get|update]_[option|meta]()` could be enhanced support both 'number',
 'int[eger]' and 'float'.

 We do PHP, HTML and JavaScript. HTML has types 'number', 'text', 'url,
 'email' and more. Some are kind of subtypes, and 'number' can be seen as a
 union type. Sometimes we need to "translate" between different
 languages/systems and contexts. We should try do that in a logical way,
 building the bridges.

 The register functions is for full and flexible sanitation and validation,
 including deep validation of arrays and objects, even pattern matching.
 This typed meta proposal, on the other hand, is far much simpler and
 focuses on PHP typing only, for performance and to avoid simple type
 errors, and paves the way to more or full strict typing overall. The two
 methods could live side by side, but we should strive to make them
 coherent, so that when both is active, no contradictions occur.

 In all languages, and many systems, there are different ways of doing
 (almost) the same thing. Hard to avoid and not necesarily so bad.

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


More information about the wp-trac mailing list