<?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;