[wp-trac] [WordPress Trac] #60355: Can't save object to metadata with `readonly` properties
WordPress Trac
noreply at wordpress.org
Mon Mar 23 11:37:32 UTC 2026
#60355: Can't save object to metadata with `readonly` properties
-------------------------------------------------+-------------------------
Reporter: Cawa-93 | Owner: (none)
Type: enhancement | Status: new
Priority: low | Milestone: Future
| Release
Component: General | Version:
Severity: major | Resolution:
Keywords: needs-docs has-patch needs-unit- | Focuses:
tests |
-------------------------------------------------+-------------------------
Comment (by abcd95):
I've been working on this and attempted to refresh the patch and tested on
PHP 8.3.30 / WP 7.0-beta6.
The original patch was almost right, but was missing a php version guard
since `ReflectionProperty::isReadOnly()` only exists on PHP 8.1+, so
calling it on lower versions would itself cause a fatal.
The fix skips readonly properties in map_deep() via continue. Since
readonly values are immutable after construction, the callback could never
have a lasting effect on them anyway and skipping would be semantically
correct.
Confirmed that:
- The unpatched map_deep() crashes with "Cannot modify readonly property"
on mixed, all-readonly, and nested-array-of-readonly objects.
- The patched version passes all cases: readonly properties are preserved,
mutable properties are still correctly transformed, and plain stdClass
objects (regression check) work exactly as before.
discussions are welcomed.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60355#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list