3v4l.org

run code in 200+ PHP versions simultaneously
<?php class A { public $state = 1; } class B { public $a; public function __construct() { $this->a = $GLOBALS['a']; } } $GLOBALS['a'] = new A(); $b = new B(); echo $b->a . PHP_EOL; $GLOBALS['a']->state++; echo $b->a . PHP_EOL; $GLOBALS['a'] = new A(); echo $b->a . PHP_EOL;
Output for 7.4.0
Fatal error: Uncaught Error: Object of class A could not be converted to string in /in/l6ai9:18 Stack trace: #0 {main} thrown in /in/l6ai9 on line 18
Process exited with code 255.
Output for 7.1.0 - 7.2.6
Recoverable fatal error: Object of class A could not be converted to string in /in/l6ai9 on line 18
Process exited with code 255.
Output for 5.6.0 - 7.0.20
Catchable fatal error: Object of class A could not be converted to string in /in/l6ai9 on line 18
Process exited with code 255.