php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33986 Using $simpleXMLElement->node as string cause bug
Submitted: 2005-08-03 21:04 UTC Modified: 2005-08-03 22:05 UTC
From: kulev dot vladimir at gmail dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.1.0b3 OS: Gentoo Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kulev dot vladimir at gmail dot com
New email:
PHP Version: OS:

 

 [2005-08-03 21:04 UTC] kulev dot vladimir at gmail dot com
Description:
------------
Maybe it's ok, because $root->node is not a string, but object.
But then PHP must return error when trying to do so, I think.

Reproduce code:
---------------
<?
$xml = "<root><node>data</node></root>";
$root = simplexml_load_string($xml);
$str = $root->node;
echo "'" . $str . "'<br/>\n";
echo "'" . $str{0} . "'<br/>\n";
echo "'" . $str{1} . "'<br/>\n";
$str = strval($root->node);
echo "'" . $str . "'<br/>\n";
echo "'" . $str{0} . "'<br/>\n";
echo "'" . $str{1} . "'<br/>\n";
?>

Expected result:
----------------
'data'
'd'
'a'
'data'
'd'
'a'

Actual result:
--------------
'data'
'data'
''
'data'
'd'
'a'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-03 22:05 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

$str = $root->node; 
echo \"\'\" . $str{0} . \"\'<br/>\\n\"; 
is the same as 
echo \"\'\" . $str[0] . \"\'<br/>\\n\"; 
so the first node is fetched whos value is \"data\". 
$str[1]\'s value NULL since there\'s only one node. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:28 2024 UTC