Edit report at https://bugs.php.net/bug.php?id=61335&edit=1
ID: 61335
User updated by: mueller at relog dot ch
Reported by: mueller at relog dot ch
-Summary: Access to "naked" node returns wrong truth value
+Summary: Access to array node returns wrong truth value
Status: Open
Type: Bug
Package: SimpleXML related
Operating System: Linux
PHP Version: 5.4.0
Block user comment: N
Private report: N
New Comment:
I forgot: Omitting the [0] array access will also fix the problem.
Previous Comments:
------------------------------------------------------------------------
[2012-03-09 17:57:50] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61335&edit=1