DOM Readonly Properties Use Asymmetric Visibility

Properties previously documented as readonly, such as DOMNode::$nodeType, DOMDocument::$xmlEncoding, DOMEntity::$actualEncoding, $encoding and $version, are now declared with asymmetric visibility (public private(set)). Writing to them from outside the class still fails, but the error message and its wording changed.

PHP code

<?php

$doc = new DOMDocument();
$doc->loadXML('<root/>');

try {
    $doc->xmlEncoding = 'UTF-8';
} catch (\Error $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}

?>

Before

Error: Cannot modify readonly property DOMDocument::$xmlEncoding

After

Error: Cannot modify private(set) property DOMDocument::$xmlEncoding from global scope

PHP version change

This behavior changed in 8.6

See Also