|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-08-17 02:37 UTC] vrana@php.net
[2007-08-19 18:37 UTC] kenashkov at gmail dot com
[2007-08-19 20:08 UTC] jani@php.net
[2010-01-07 12:25 UTC] svn@php.net
[2010-01-07 12:25 UTC] kalle@php.net
[2020-02-07 06:09 UTC] phpdocbot@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 12:00:02 2025 UTC |
Description: ------------ Testing an SimpleXMLElement object for children is unconsistent. Here is an example: -------- $str = '<rootnode><subnode></subnode></rootnode>'; $x = new SimpleXMLElement($str); if($x->subnode->children()) print 'yes'; else print 'no'; --------- will print 'no'; If the $str='<rootnode><subnode><newnode></newnode></subnode></rootnode>'; it will print yes. But the same will happen if the subnode has an attribute like: $str = '<rootnode><subnode id="2"></subnode></rootnode>'; But if we use foreach($x->subnode->children() as $key=>$value) in the latter example we will not get anything (which is correct). I think is wrong the children() method to return object when there are no child objects and the node has attributes (because for querying the attributes we have the attributes() method). This was discussed in php-dev list - http://marc.info/?l=php-dev&m=118001203709813&w=2 If this is not a bug, I think a note regarding this behaviour must be added in the docs. Reproduce code: --------------- $str = '<rootnode><subnode id="2"></subnode></rootnode>'; $x = new SimpleXMLElement($str); if($x->subnode->children()) print 'yes'; else print 'no'; Expected result: ---------------- no Actual result: -------------- yes