3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { public $x; public $y; public function __construct($x, $y) { $this->x = sha1($x); $this->y = $y; } public function __clone() { return new A($this->x, $this->y); } } class B extends A { public $z; public function __construct($z, $parent_obj) { $this->z = $z; parent::__construct($parent_obj->x, $parent_obj->y); } public function doSomeThing() { $parent_a_array = (array) parent::__clone(); var_dump($parent_a_array); $child_a_array = array_diff_assoc((array) $this, $parent_a_array); var_dump($child_a_array); echo "Parent Array Printing :\n"; foreach ($parent_a_array as $key => $value) { echo "Key: $key; Value: $value\n"; } echo "\nChild Array Printing: \n"; foreach ($child_a_array as $key => $value) { echo "Key: $key; Value: $value\n"; } } } $t = new B('C', new A("A", "B")); $t->doSomeThing();
based on uN9dA
Output for 5.6.0 - 7.3.0alpha1
array(2) { ["x"]=> string(40) "726c6aeb8252ad589562fe2c7409d50c90a058aa" ["y"]=> string(1) "B" } array(2) { ["z"]=> string(1) "C" ["x"]=> string(40) "bd605412133b28b10c5fa7a45fce29df67c18bd7" } Parent Array Printing : Key: x; Value: 726c6aeb8252ad589562fe2c7409d50c90a058aa Key: y; Value: B Child Array Printing: Key: z; Value: C Key: x; Value: bd605412133b28b10c5fa7a45fce29df67c18bd7