3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class demo { public $n = 0; function __construct() { $this->n =& $this->n; } function magic() { if ($this->n) return; } function set($n) { $this->n = $n; } } // Outputs 1 = 1 as expected $a1 = new demo(); $b1 = clone $a1; $a1->magic(); $b1->set(1); echo "{$a1->n} = {$b1->n}\n"; // Outputs 0 = 1 (magic() method is called a little earlier) $a2 = new demo(); $a2->magic(); $b2 = clone $a2; $b2->set(1); echo "{$a2->n} = {$b2->n}\n";
Output for 7.0.0 - 7.2.0
0 = 1 0 = 1
Output for 5.3.21 - 5.6.28
1 = 1 0 = 1