3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class SubObject { static $instances = 0; public $instance; public function __construct() { $this->instance = ++self::$instances; echo self::$instances; } public function __clone() { $this->instance = ++self::$instances; } } class MyCloneable { /* public $object1; public $object2; */ function __clone() { // forza la copia di $this->object1, che altrimenti // punterebbe alla stessa istanza. $this->object1 = clone $this->object1; } public function __invoke($object1,$object2) { $this->oject1=$object1; $this->oject2=$object2; } } $obj = new MyCloneable(); $obj->object1 = new SubObject(); $obj->object2 = new SubObject(); $obj2=new $obj; $obj2->object1 = new SubObject(); $obj2->object2 = new SubObject(); $obj3 = clone $obj; print("Oggetto originale:\n"); print_r($obj); print("Oggetto originale:\n"); print_r($obj2); print("Oggetto clonato:\n"); print_r($obj3); echo SubObject::$instances; ?>

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for Typed properties v2
1234Oggetto originale: MyCloneable Object ( [object1] => SubObject Object ( [instance] => 1 ) [object2] => SubObject Object ( [instance] => 2 ) ) Oggetto originale: MyCloneable Object ( [object1] => SubObject Object ( [instance] => 3 ) [object2] => SubObject Object ( [instance] => 4 ) ) Oggetto clonato: MyCloneable Object ( [object1] => SubObject Object ( [instance] => 5 ) [object2] => SubObject Object ( [instance] => 2 ) ) 5
Output for Lexical anon
1234Oggetto originale: MyCloneable Object ( [object1] => SubObject Object ( [instance] => 1 ) [object2] => SubObject Object ( [instance] => 2 ) ) Oggetto originale: MyCloneable Object ( [object1] => SubObject Object ( [instance] => 3 ) [object2] => SubObject Object ( [instance] => 4 ) ) Oggetto clonato: MyCloneable Object ( [object1] => SubObject Object ( [instance] => 5 ) [object2] => SubObject Object ( [instance] => 2 ) ) 5

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page