[php-src] Issue #15578: Readonly liskov violations in new Dom API
| From: | jnvsor | Date: | Sun, 25 Aug 2024 00:38:36 +0000 |
| Subject: | [php-src] Issue #15578: Readonly liskov violations in new Dom API | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247586@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15578
Author: jnvsor
### Description
The following code:
```php
<?php
$xml = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child />
</root>
END;
$doc = Dom\XMLDocument::createFromString($xml);
$root = $doc->firstChild;
$text = $root->firstChild;
$child = $root->firstElementChild;
try {
$text->nodeValue = 'Hello';
} catch (Throwable $t) {
var_dump($t->getMessage());
}
try {
$child->nodeValue = 'Hello';
} catch (Throwable $t) {
var_dump($t->getMessage());
}
try {
$doc->nodeValue = 'Hello';
} catch (Throwable $t) {
var_dump($t->getMessage());
}
try {
$text->textContent = 'Hello';
} catch (Throwable $t) {
var_dump($t->getMessage());
}
try {
$child->textContent = 'Hello';
} catch (Throwable $t) {
var_dump($t->getMessage());
}
try {
$doc->textContent = 'Hello';
} catch (Throwable $t) {
var_dump($t->getMessage());
}
```
Resulted in this output:
```
string(55) "Cannot modify readonly property Dom\Element::$nodeValue"
string(59) "Cannot modify readonly property Dom\XMLDocument::$nodeValue"
string(61) "Cannot modify readonly property Dom\XMLDocument::$textContent"
```
But I expected this output instead:
```
```
In user code this would result in:
> Fatal error: Cannot redeclare non-readonly property X::$y as readonly Y::$y
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](https://3v4l.org/4fQ63/rfc#vgit.master)
### PHP Version
8.4.0beta3
### Operating System
_No response_