Fix #71872: PHP registerNodeClass and reusing variable names

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@351280 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Christoph Michael Becker 2020-11-06 11:02:11 +00:00
parent adcfa45072
commit c410fb8895

View file

@ -174,6 +174,46 @@ var_dump(get_class($child->ownerDocument));
<![CDATA[
string(13) "myDOMDocument"
string(18) "myOtherDOMDocument"
]]>
</screen>
</example>
</para>
<para>
<example xml:id="domdocument.registernodeclass.example.transient">
<title>Custom objects are transient</title>
<caution>
<simpara>
Objects of the registered node classes are transient, i.e. they are
destroyed when they are no longer referenced from PHP code, and recreated
when being retrieved again. That implies that custom property values will be
lost after recreation.
</simpara>
</caution>
<programlisting role="php">
<![CDATA[
<?php
class MyDOMElement extends DOMElement
{
public $myProp = 'default value';
}
$doc = new DOMDocument();
$doc->registerNodeClass('DOMElement', 'MyDOMElement');
$node = $doc->createElement('a');
$node->myProp = 'modified value';
$doc->appendChild($node);
echo $doc->childNodes[0]->myProp, PHP_EOL;
unset($node);
echo $doc->childNodes[0]->myProp, PHP_EOL;
?>]]>
</programlisting>
&example.outputs;
<screen role="xml">
<![CDATA[
modified value
default value
]]>
</screen>
</example>