Fix GH-21768: ext/reflection: assertion failure on internal virtual p…#21769
Fix GH-21768: ext/reflection: assertion failure on internal virtual p…#21769devnexen wants to merge 2 commits intophp:masterfrom
Conversation
…l properties. ReflectionProperty::isReadable() and isWritable() asserted prop->hooks being set whenever ZEND_ACC_VIRTUAL is set. Internal classes such as DOMDocument declare virtual properties backed by the object read/write handlers without hooks, tripping the assertion. Assertion introduced in e4f727d.
|
So this solves the assertion failure. But I wonder what this new reflection method actually tests... I.e. the following code will throw: <?php
$dom = new DOMDocument;
$dom->doctype = null; // Error!but it claims this property is writable: <?php
$rc = new ReflectionClass($dom);
var_dump($rc->getProperty('doctype')->isWritable(null)); // bool(true) |
|
Fair point, returning true for read-only props like doctype is misleading. I'm not sure what the right call is here. Would it make more sense to fix this on the DOM side, giving these @virtual properties proper get-only hooks so reflection can answer correctly, rather than working As a narrow alternative for the crash-fix, we could throw ReflectionException whenever the property is ZEND_ACC_VIRTUAL without hooks, something like "Cannot Happy to go either way, or hold off on this PR if you'd rather sort it at the DOM level. |
|
The properties of dom that aren't writable are marked as readonly. This isn't really right as some dom manipulations can change those properties indirectly anyway. This is a leftover from back in the days. |
@readonly on DOM property stubs was documentation only and did not translate to any runtime flag, so reflection reported the properties as writable while the write_property handler threw on assignment. Declaring them public private(set) lets the engine reject external writes via the normal visibility check and lets ReflectionProperty:: isWritable() answer honestly. Also drops @readonly from the three non-virtual HTMLCollection $children properties (Element, DocumentFragment, Document) and applies private(set) there as well. Depends on the assertion removal from phpGH-21769 for isReadable() to stop aborting on these properties.
…roperties.
ReflectionProperty::isReadable() and isWritable() asserted prop->hooks being set whenever ZEND_ACC_VIRTUAL is set. Internal classes such as DOMDocument declare virtual properties backed by the object read/write handlers without hooks, tripping the assertion.
Assertion introduced in e4f727d.