[wp-trac] [WordPress Trac] #60355: Can't save object to metadata with `readonly` properties
WordPress Trac
noreply at wordpress.org
Mon Feb 12 15:08:49 UTC 2024
#60355: Can't save object to metadata with `readonly` properties
-------------------------+---------------------
Reporter: Cawa-93 | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.5
Component: General | Version:
Severity: minor | Resolution:
Keywords: needs-docs | Focuses:
-------------------------+---------------------
Comment (by swissspidy):
> Think this is a documentation problem in WP. Imho the docblocks for
adding options and meta should state clearly that saving class instances
or PHP objects to the DB is not recommended and that only simple objects
are supported (like plain name->value pairs?). Also that the preferable
format to save to the DB are strings or associative arrays, not objects.
Big +1 to this. Storing class instances in database usually causes more
harm than good. Not only can it cause issues like this, but it can also
inflate the database size and cause potential security issues.
As for the patch, it would need a slight update to not crash on PHP 7.0+,
as `isReadOnly()` is only available since 8.1.
@abditsori FYI, no need to upload a patch file _and_ submit a PR. A PR is
enough.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60355#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list