Skip to content

Readonly liskov violations in new Dom API #15578

Description

@jnvsor

Description

The following code:

<?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

PHP Version

8.4.0beta3

Operating System

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions