3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class U extends ArrayObject { public function __construct($input, $flags = 0) { parent::__construct($input, $flags); } //public $id; //public $name; } $a = ['id' => 123, 'name' => 'Me']; $o = (object)$a; var_dump($o); $ao0 = new ArrayObject($a); $ao1 = new ArrayObject($a, ArrayObject::STD_PROP_LIST); $ao2 = new ArrayObject($a, ArrayObject::ARRAY_AS_PROPS); $ao3 = new ArrayObject($a, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); $ao3x = new ArrayObject($a, ArrayObject::STD_PROP_LIST & ArrayObject::ARRAY_AS_PROPS); $u0 = new U($a); $u1 = new U($a, ArrayObject::STD_PROP_LIST); $u2 = new U($a, ArrayObject::ARRAY_AS_PROPS); $u3 = new U($a, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); $u3x = new U($a, ArrayObject::STD_PROP_LIST & ArrayObject::ARRAY_AS_PROPS); var_dump($ao0); var_dump($u0); echo '-----'; var_dump($ao0->name); var_dump($ao1->name); var_dump($ao2->name); var_dump($ao3->name); var_dump($ao3x->name); echo '---'; var_dump($ao0['name']); var_dump($ao1['name']); var_dump($ao2['name']); var_dump($ao3['name']); var_dump($ao3x['name']); echo '-----'; var_dump($u0->name); var_dump($u1->name); var_dump($u2->name); var_dump($u3->name); var_dump($u3x->name); echo '---'; var_dump($u0['name']); var_dump($u1['name']); var_dump($u2['name']); var_dump($u3['name']); var_dump($u3x['name']); echo "-----\n"; var_dump(is_array($o)); var_dump(is_array($ao2)); var_dump(is_array($u2)); echo "-----\n"; var_dump($o instanceof Iterator); var_dump($ao2 instanceof Iterator); var_dump($u2 instanceof Iterator); echo "-----\n"; var_dump(is_object($o)); var_dump(is_object($ao2)); var_dump(is_object($u2));
based on FlMUA
Output for 5.6.0 - 7.3.0beta1
object(stdClass)#1 (2) { ["id"]=> int(123) ["name"]=> string(2) "Me" } object(ArrayObject)#2 (1) { ["storage":"ArrayObject":private]=> array(2) { ["id"]=> int(123) ["name"]=> string(2) "Me" } } object(U)#7 (1) { ["storage":"ArrayObject":private]=> array(2) { ["id"]=> int(123) ["name"]=> string(2) "Me" } } ----- Notice: Undefined property: ArrayObject::$name in /in/fdKLB on line 32 NULL Notice: Undefined property: ArrayObject::$name in /in/fdKLB on line 33 NULL string(2) "Me" string(2) "Me" Notice: Undefined property: ArrayObject::$name in /in/fdKLB on line 36 NULL ---string(2) "Me" string(2) "Me" string(2) "Me" string(2) "Me" string(2) "Me" ----- Notice: Undefined property: U::$name in /in/fdKLB on line 49 NULL Notice: Undefined property: U::$name in /in/fdKLB on line 50 NULL string(2) "Me" string(2) "Me" Notice: Undefined property: U::$name in /in/fdKLB on line 53 NULL ---string(2) "Me" string(2) "Me" string(2) "Me" string(2) "Me" string(2) "Me" ----- bool(false) bool(false) bool(false) ----- bool(false) bool(false) bool(false) ----- bool(true) bool(true) bool(true)