3v4l.org

run code in 300+ PHP versions simultaneously
<?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; } } $test = new MyObject( 'hihi' ); $test->foo(); var_dump(MyObject::$_register);

preferences:
44.73 ms | 402 KiB | 5 Q