Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #55942, comment 74


Ignore:
Timestamp:
05/07/2023 08:01:37 PM (17 months ago)
Author:
azaozz
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #55942, comment 74

    initial v1  
    55This, of course, will not fix the current "weirdness" with the options and meta APIs where you save `true` but get back `(string) 1` (which is the same as when you save `(int) 1`). However it will eliminate calls to `maybe_unserialize()` for updated and newly added options and meta values. I'm personally not a big fan of this, but it is a viable solution too.
    66
    7 This would also open the door to consider JSON encoding all values except class instances when storing them in the DB. That would "enforce" strict types because JSON encoding preserves the data type (`$data = json_encode( true )` then `json_decode( $data )` would return `true`). This will fix the above mentioned "weirdness".
     7This would also open the door to consider JSON encoding all values except strings and class instances when storing them in the DB. That would "enforce" strict types because JSON encoding preserves the data type (`$data = json_encode( true )` then `json_decode( $data )` would return `true`). This will fix the above mentioned "weirdness".
    88
    99There would be a tiny bit of increase in resources used, but it would probably be negligible as `json_decode()` for arrays seems faster than `unserialize()` and for `int` and `bool` is super fast. Haven't tested with production databases but expecting the faster decoding of arrays will compensate the need to decode boolean, integer and float values.