3v4l.org

run code in 200+ php & hhvm versions
<?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->state . PHP_EOL; $GLOBALS['a']->state++; echo $b->a->state . PHP_EOL; $GLOBALS['a'] = new A(); echo $b->a->state . PHP_EOL; echo $GLOBALS['a']->state . PHP_EOL;
based on eTaI5
Output for 5.6.0 - 7.2.6
1 2 2 1