|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-08-19 00:32 UTC] ken at smallboxcms dot com
Description:
------------
Variables added to dom nodes are later unset. This behaviour does not appear to happen with other types of PHP objects.
Test script:
---------------
<?php
$blah = new stdClass;
function humbug()
{
/* Behaviour changes when uncommented. Think this is a GC bug.
global $node;
*/
global $blah;
$doc = new domDocument('1.0', 'utf-8');
$blah->doc = $doc;
$node = $doc->createElement('node');
$doc->appendChild($node);
$node->foo = true;
$obj = new stdClass;
$blah->obj = $obj;
$obj->child = new stdClass;
$obj->child->foo = true;
}
humbug();
echo "Should be set: ".$blah->doc->firstChild->foo."<BR>\n";
echo "Is Set: ".$blah->obj->child->foo."<BR>\n";
?>
Expected result:
----------------
I would expect that $blah->doc->firstChild->foo would be set after the function call.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 05:00:01 2025 UTC |
Well, to my way of thinking the the XML document is expressed as a PHP object so it should behave as one in every respect. Here is an example where there is a distinct difference in that behaviour, one that would be unexpected by a PHP programmer who is not intimately acquainted with PHP's internals. I am fairly certain that this difference is undocumented. Here is another example which more clearly illustrates the problem. <?php $blah = new stdClass; function humbug() { /* Behaviour changes when uncommented. Think this is a GC bug. global $node; */ global $blah; $doc = new domDocument('1.0', 'utf-8'); $blah->doc = $doc; $node = $doc->createElement('node'); $doc->appendChild($node); $node->foo = true; $obj = new stdClass; $blah->obj = $obj; $obj->child = new stdClass; $obj->child->foo = true; echo "Why is this set: ".$blah->doc->firstChild->foo."<BR>"; } humbug(); echo "When this is not set: ".$blah->doc->firstChild->foo."<BR>\n"; echo "This is Set: ".$blah->obj->child->foo."<BR>\n"; ?>