note 95224 modified in simplexml.examples by danbrown
| From: | danbrown@php.net | Date: | Wed, 06 Oct 2010 14:50:24 +0000 |
| Subject: | note 95224 modified in simplexml.examples by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173019@lists.php.net to get a copy of this message | ||
When using simplexml to access a element the returned object may be a SimpleXMLElement instead of a
string.
Example:
<?php
$string = <<<XML
<?xml version='1.0'?>
<document>
<cmd>login</cmd>
<login>Richard</login>
</document>
XML;
$xml = simplexml_load_string($string);
print_r($xml);
$login = $xml->login;
print_r($login);
$login = (string) $xml->login;
print_r($login);
?>
Expected result:
----------------
SimpleXMLElement Object
(
[cmd] => login
[login] => Richard
)
Richard
Richard
Actual result:
--------------
SimpleXMLElement Object
(
[cmd] => login
[login] => Richard
)
SimpleXMLElement Object
(
[0] => Richard
)
Richard
But this is an intended behavior. See http://bugs.php.net/bug.php?id=29500
--was--
When using simplexml to access a element the returned object may be a SimpleXMLElement instead of a
string.
Example:
<? php
$string = <<<XML
<?xml version='1.0'?>
<document>
<cmd>login</cmd>
<login>Richard</login>
</document>
XML;
$xml = simplexml_load_string($string);
print_r($xml);
$login = $xml->login;
print_r($login);
$login = (string) $xml->login;
print_r($login);
?>
Expected result:
----------------
SimpleXMLElement Object
(
[cmd] => login
[login] => Richard
)
Richard
Richard
Actual result:
--------------
SimpleXMLElement Object
(
[cmd] => login
[login] => Richard
)
SimpleXMLElement Object
(
[0] => Richard
)
Richard
But this is an intended behavior. See http://bugs.php.net/bug.php?id=29500
http://php.net/manual/en/simplexml.examples.php