mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
adcfa45072
commit
c410fb8895
1 changed files with 40 additions and 0 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue