I am a newcomer to PHP and SimpleXMl.
I would not expect false under either of these tests.
$xml=new SimpleXMLElement('<a><b>123</b></a>');
var_dump($xml);
echo $xml ? "true": "false";
or
$xml=new SimpleXMLElement('<a><b></b></a>');
var_dump($xml);
echo $xml ? "true": "false";
however the second returns false even though an XMLSimpleElement object is returned.
I have the same issue with an xml doc with namespaces everywhere.
it means I cannot test for a failed XML parsing as
if (!xml) returns false
but $xml->childen($namespace) does not.
Please advise
TIA
Ephraim
I can’t reproduce your issue but I’ll try to provide a couple of hints.
First, here’s the rule when converting objects to booleans:
Second, the SimpleXMLElement constructor always returns an object but it can throw a warning and an exception.
So these are the possibilities: