3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $xml = new SimpleXMLElement('<tag></tag>'); var_dump((bool) $xml); if($xml) { echo 'An empty SimpleXMLElement is truthy'; } else { echo 'An empty SimpleXMLElement is falsey'; } echo "\n"; $xml = new SimpleXMLElement('<tag>data</tag>'); if($xml) { echo 'A SimpleXMLElement with data is truthy'; } else { echo 'A SimpleXMLElement with data is falsey'; } echo "\n"; $obj = new stdClass(); if($obj) { echo 'An empty stdClass is truthy'; } else { echo 'An empty stdClass is falsey'; }
based on Sa5NJ
Output for 5.1.0 - 7.1.7
bool(false) An empty SimpleXMLElement is falsey A SimpleXMLElement with data is truthy An empty stdClass is truthy
Output for 5.0.0 - 5.0.5
bool(false) An empty SimpleXMLElement is truthy A SimpleXMLElement with data is truthy An empty stdClass is truthy
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/Q8YKF on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/Q8YKF on line 2