|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61335 Access to array node returns wrong truth value
Submitted: 2012-03-09 17:57 UTC Modified: 2015-05-27 17:51 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: mueller at relog dot ch Assigned: cmb (profile)
Status: Duplicate Package: SimpleXML related
PHP Version: 5.4.0 OS: Linux
Private report: No CVE-ID: None
 [2012-03-09 17:57 UTC] mueller at relog dot ch
When accessing a simplexml node as array, I always get an empty simplexml object. 

If I cast the node to string, the behaviour is correct. 

If the parent node contains nothing but the child node (not even a newline) then 
the behaviour is also correct.

Under php 5.3, the behaviour is correct.

Test script:
$rec1 = simplexml_load_string("<foo><bar>aa</bar>\n</foo>");
$rec2 = simplexml_load_string("<foo><bar>aa</bar></foo>");

if ($rec1->bar[0])      echo "NONEMPTY1\n"; # not reached, bug
if ($rec1->bar[0] . "") echo "NONEMPTY2\n"; # correct
if ($rec2->bar[0])      echo "NONEMPTY3\n"; # correct

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-09 18:00 UTC] mueller at relog dot ch
-Summary: Access to "naked" node returns wrong truth value +Summary: Access to array node returns wrong truth value
 [2012-03-09 18:00 UTC] mueller at relog dot ch
I forgot: Omitting the [0] array access will also fix the problem.
 [2012-03-10 00:00 UTC] me at ktamura dot com
I think this bug is related to
 [2012-03-13 13:19 UTC] mueller at relog dot ch
The other bug is said to have been fixed in svn, however my bug still happens in 
the current version from svn.
 [2012-03-13 13:50 UTC] cschneid at cschneid dot com
It seems commit 311171 broke it:
 [2015-05-26 19:28 UTC]
-Status: Open +Status: Verified
 [2015-05-26 19:28 UTC]
Related to bug #67572 and bug #68946.
 [2015-05-26 19:57 UTC]
Simplified test case: <>.
 [2015-05-27 17:51 UTC]
-Status: Verified +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-05-27 17:51 UTC]
After further investigation it turned out that this is a duplicate
of bug #66084.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 02:01:30 2024 UTC