#41662 [Fbk->Opn]: SimpleXML->children() misleading result
| From: | kenashkov at gmail dot com | Date: | Sun, 19 Aug 2007 18:37:29 +0000 |
| Subject: | #41662 [Fbk->Opn]: SimpleXML->children() misleading result | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116319@lists.php.net to get a copy of this message | ||
ID: 41662
User updated by: kenashkov at gmail dot com
Reported By: kenashkov at gmail dot com
-Status: Feedback
+Status: Open
Bug Type: SimpleXML related
Operating System: Fedora Core 4
-PHP Version: 5.2.3
+PHP Version: 5.2.4RC3-dev
New Comment:
Still the same result with 5.2.4RC3-dev.
Previous Comments:
------------------------------------------------------------------------
[2007-08-17 13:38:37] jani@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows (zip):
http://snaps.php.net/win32/php5.2-win32-latest.zip
For Windows (installer):
http://snaps.php.net/win32/php5.2-win32-installer-latest.msi
------------------------------------------------------------------------
[2007-08-17 02:37:22] vrana@php.net
There's no reason why a node without subnode should return anything in
its children(). Especially if there is attributes() method returning
attributes. Please fix the sources.
------------------------------------------------------------------------
[2007-06-12 07:36:50] kenashkov at gmail dot com
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41662&edit=1