Am I just completely missing something with this SimpleXML functions?

Something else I noticed that seems broken to me... 
I can change the "if ($xml->error)" line to "if ($xml->foo)" 
and I still get the text echo'd to the screen. ?!!?!

If I change it to "if ($xml->error->code)" then I don't get the text.
Which sort of makes sense, since there is 
no "$xml->error" object in the var_dump. 

"if (is_object($xml->error))" also return true and outputs the text.

object(SimpleXMLElement)#1 (2) {
  ["code"]=>
  string(3) "tbd"
  ["string"]=>
  string(38) "user not found."
}

The way that I've hacked around this for now is 
"if ( (string)$xml->code != '')"

Ideas on what I'm doing wrong, or is this function just completely bunk.

> -----Original Message-----
> Here is a code fragment I use:
> 
> $xml = simplexml_load_string($returnData);
> var_dump($xml);
> if (is_object($xml))
> {
>       //first lets make sure we didn't get an <ERROR>
>       if ($xml->error)
>       {
>               echo "An ERROR was encountered\n";
>               echo "CODE: ".((string)$xml->error->code)."\n";
>               echo "STRING: ".((string)$xml->error->string)."\n";
>               exit;
>       }
> 
>       ...
> }

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to