Тип несуществующих SimpleXMLElements ⇐ Php
-
Anonymous
Тип несуществующих SimpleXMLElements
Can you explain me the reason why SimpleXMLElement returns an empty object for non-existent XML-elements on the first level, but not for any layer below?
See this code:
$xml = simplexml_load_string(''); echo "Type of A: " . gettype($xml->Foo->A) . PHP_EOL; // object echo "Type of B: " . gettype($xml->Foo->A->B) . PHP_EOL; // NULL echo "Type of C: " . gettype($xml->Foo->A->B->C) . PHP_EOL; // Warning because of property access on NULL var_dump($xml->Foo->A); //object(SimpleXMLElement)#4 (0) {}
Источник: https://stackoverflow.com/questions/780 ... mlelements
Can you explain me the reason why SimpleXMLElement returns an empty object for non-existent XML-elements on the first level, but not for any layer below?
See this code:
$xml = simplexml_load_string(''); echo "Type of A: " . gettype($xml->Foo->A) . PHP_EOL; // object echo "Type of B: " . gettype($xml->Foo->A->B) . PHP_EOL; // NULL echo "Type of C: " . gettype($xml->Foo->A->B->C) . PHP_EOL; // Warning because of property access on NULL var_dump($xml->Foo->A); //object(SimpleXMLElement)#4 (0) {}
Источник: https://stackoverflow.com/questions/780 ... mlelements