php.net |  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
Votes:1
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
Description:
------------
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:
----------------
NONEMPTY1
NONEMPTY2
NONEMPTY3


Actual result:
--------------
NONEMPTY2
NONEMPTY3


Patches

Pull Requests

History

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 https://bugs.php.net/bug.php?id=51615
 [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:
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_4/ext/simplexml/simplexml.c?r1=311171&r2=311170&pathrev=311171
 [2015-05-26 19:28 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-05-26 19:28 UTC] cmb@php.net
Related to bug #67572 and bug #68946.
 [2015-05-26 19:57 UTC] cmb@php.net
Simplified test case: <http://3v4l.org/bUncK>.
 [2015-05-27 17:51 UTC] cmb@php.net
-Status: Verified +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-05-27 17:51 UTC] cmb@php.net
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: Fri Dec 13 21:01:27 2024 UTC