3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyObject{ public static $_register = array(); public $_id = -1; public $_value = ''; function __construct( $value ){ $this->_value = $value; $this->_id = count( self::$_register ); var_dump($this); self::$_register[ $this->_id ] = &$this; // I also tried '= &$this' } function foo(){ // outputs 'id : value' echo $this->_id.' : ' . $this->_value. PHP_EOL; } function __destruct() { } } $test = new MyObject( 'hihi' ); $test->foo(); var_dump(MyObject::$_register); MyObject::$_register[0]->__destruct(); var_dump($test);
Output for 5.0.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
object(MyObject)#1 (2) { ["_id"]=> int(0) ["_value"]=> string(4) "hihi" } 0 : hihi array(1) { [0]=> object(MyObject)#1 (2) { ["_id"]=> int(0) ["_value"]=> string(4) "hihi" } } object(MyObject)#1 (2) { ["_id"]=> int(0) ["_value"]=> string(4) "hihi" }
Output for 5.0.0 - 5.0.1
object(MyObject)#1 (2) { ["_id"]=> int(0) ["_value"]=> string(4) "hihi" } Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/5iAtr on line 15 0 : hihiPHP_EOLarray(1) { [0]=> object(MyObject)#1 (2) { ["_id"]=> int(0) ["_value"]=> string(4) "hihi" } } object(MyObject)#1 (2) { ["_id"]=> int(0) ["_value"]=> string(4) "hihi" }
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/5iAtr 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/5iAtr 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/5iAtr on line 3
Process exited with code 255.