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
 [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

Pull Requests

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: Sat Dec 21 13:01:31 2024 UTC