<?php
class U {
public $id;
public $name;
}
$a = ['id' => 123, 'name' => 'Me'];
$o = (object)$a;
var_dump($o);
$a0 = new ArrayObject($a);
$a1 = new ArrayObject($a, ArrayObject::STD_PROP_LIST);
$a2 = new ArrayObject($a, ArrayObject::ARRAY_AS_PROPS);
$a3 = new ArrayObject($a, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
$a3x = new ArrayObject($a, ArrayObject::STD_PROP_LIST & ArrayObject::ARRAY_AS_PROPS);
var_dump($a0);
var_dump($a1);
var_dump($a2);
var_dump($a3);
var_dump($a3x);
- Output for 5.6.0 - 5.6.27, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
- 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(ArrayObject)#3 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["id"]=>
int(123)
["name"]=>
string(2) "Me"
}
}
object(ArrayObject)#4 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["id"]=>
int(123)
["name"]=>
string(2) "Me"
}
}
object(ArrayObject)#5 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["id"]=>
int(123)
["name"]=>
string(2) "Me"
}
}
object(ArrayObject)#6 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["id"]=>
int(123)
["name"]=>
string(2) "Me"
}
}
preferences:
224.42 ms | 405 KiB | 234 Q