SimpleXML returns false positives

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux