I'm looking for feedback since this is my first commit to PHP and it changes some behavior of SimpleXMLElement. If no-one has an objections I'll go ahead and commit the code.
First, here is the original bug: -------BEGIN------ $string = '<?xml version="1.0"?> <foo><bar> <p>Blah 1</p> <p>Blah 2</p> <p>Blah 3</p> <tt>Blah 4</tt> </bar></foo> '; $foo = simplexml_load_string($string); $p = $foo->bar->p; echo count($p); $p = (array)$foo->bar->p; echo count($p); --------END-------- The output should be 33 but is 31 instead. If you do a var_dump() of $p you get this: -------BEGIN------ array(1) { [0]=> string(6) "Blah 1" } --------END-------- With my updated code you get this: -------BEGIN------ array(3) { [0]=> string(6) "Blah 1" [1]=> string(6) "Blah 2" [2]=> string(6) "Blah 3" } --------END-------- The same also applies if you do a var_dump() of "->p" directly (without the cast). In the current releases, the dump will contain only the first child node and not the second and third. But with my fix in place it will contain all child nodes. All the other behavior is unchanged. The code did break one test. The test for bug #51615 expected the var_dump() to contain only one child node, where the new code outputs (correctly, I think) all child nodes. So I also changed that test to have the new expected output. It does change in the behavior of var_dump() on SimpleXMLElement. Which may break people who depend on this bug (if there is anyone). However, I believe the new behavior is correct. Since in the current release code, var_dump() excludes valid object properties. The way I fixed it was to detect if the node is part of node iterator (for lack of a better word) which is meant to loop over some but not all children of a node. If it is, then I use the SimpleXML iterator functions for traversal when getting the properties hash. If it isn't, then I just use the trusty "ptr->next" method. Taking care to store and then restore the existing iterator data so as to not break any outer loops. I attached a diff of my changes. Any thoughts? -- Andrew
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php