add a note

User Contributed Notes 1 note

up
38
Juan Herrera
15 years ago
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

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
To Top

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant