-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Readonly liskov violations in new Dom API #15578
Comments
At least part of the problem is that these are not readonly properties, but rather more like getter hooks (see #15553). |
That would indeed be allowed if following hook semantics: https://3v4l.org/b2LS3/rfc#vgit.master In any case, the behaviour is correct according to spec. If we take a look at $nodeValue for example: https://dom.spec.whatwg.org/#dom-node-nodevalue. We can see that only 2 subclasses have a writable $nodeValue property while for the others it's readonly. So the way to move forward with this is by doing the following 2 changes:
|
@nielsdos You're setting on the parent class not the child, so the hook semantics are adhering to liskov: https://3v4l.org/t5ebW/rfc#vgit.master Although the empty setter makes it a no-op, it went from readonly in the parent to writable in the child. While that's not possible with the If we flip them around to be analogous the child just uses the parent's setter: https://3v4l.org/8ig6M/rfc#vgit.master I don't know what the right solution is but I suspect it'd be a Edit: Actually isn't that the solution? Just make |
I believe we're just saying the same thing but in different words.
That's how it's implemented right now. It's just the "readonly annotation that's not actually the same as the readonly keyword" that causes confusion. |
In that case yes, it's a documentation error. The part that confused me is that it's not marked readonly on Line 136 in b9b317a
If you could mark it readonly on If the docs are getting a way to render property hooks then this is probably a good example of where to use them |
The comments in the C source code don't have any influence on the semantics or the docs. The docs are rendered from the stub file. I think those readonly comments should be removed anyway as they are from legacy DOM and are confusing. |
They are readonly / not readonly depending on the class where they're used. However, the comment makes this confusing [1]. [1] #15578 (comment)
Or, now that we have aviz, something much more simpler and technically correct: make them |
@nielsdos If an exception is made for this API to allow dom subclasses to have widened visibility that would make perfect sense, but I'm not sure replacing one inheritance rule violation with another one is the best solution. A virtual property without a defined setter reproduces current behavior properly however: https://3v4l.org/CRYJa#v8.4.1 |
Ah right indeed, good points... |
Description
The following code:
Resulted in this output:
But I expected this output instead:
In user code this would result in:
Since I've found multiple of these exploring the new Dom API it probably needs a closer look.
Tested in both docker (php:8.4-rc-alpine version 8.4.0beta3) and 3v4l
PHP Version
8.4.0beta3
Operating System
No response
The text was updated successfully, but these errors were encountered: