3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class UberSimpleXML extends SimpleXMLElement { public function __toString() { return 'stringification'; } } $xml = new UberSimpleXML('<xml/>'); $xml->tag = "you're it!"; echo "\nno cast\n"; echo $xml; echo "\ncast\n"; echo (string) $xml; echo "\nexplicit call\n"; echo $xml->__toString(); echo "\n"; var_dump((string) $xml); var_dump($xml->__toString());
Output for 5.4.7 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
no cast stringification cast stringification explicit call stringification string(15) "stringification" string(15) "stringification"
Output for 5.0.0 - 5.3.21, 5.4.0 - 5.4.6
no cast stringification cast explicit call stringification string(0) "" string(15) "stringification"
Output for 5.3.22 - 5.3.29
no cast cast explicit call stringification string(0) "" string(15) "stringification"
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ClBPj on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ClBPj on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/ClBPj on line 3
Process exited with code 255.