3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { public $v; private static $_cli; private function __construct() { } public static function getCli() { if (!self::$_cli instanceof self) { self::$_cli = new self(); } return self::$_cli; } // override __clone() to private private function __clone() { } } $c1 = A::getCli(); $c1->v = 1; $c2 = $c1; $c2->v = 2; $c3 = clone $c1; $c3->v = 3; var_dump($c1->v, $c2->v, $c3->v);
based on lqRe6
Output for 7.0.0 - 7.3.0rc3
Fatal error: Uncaught Error: Call to private A::__clone() from context '' in /in/QEWFA:27 Stack trace: #0 {main} thrown in /in/QEWFA on line 27
Process exited with code 255.
Output for hhvm-3.12.14 - 3.17.3
int(2) int(2) int(3)
Output for 5.6.0 - 5.6.30
Fatal error: Call to private A::__clone() from context '' in /in/QEWFA on line 27
Process exited with code 255.