-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathSplFixedArray_get_properties_for.phpt
85 lines (85 loc) · 2.02 KB
/
SplFixedArray_get_properties_for.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--TEST--
SplFixedArray - get_properties_for handlers
--FILE--
<?php
#[AllowDynamicProperties]
class MySplFixedArray extends SplFixedArray {
public $x;
public int $y;
}
class X {}
class Y {}
$array = new MySplFixedArray(2);
var_dump(get_mangled_object_vars($array));
$array[0] = new stdClass();
$array[1] = new Y();
$array->x = new SplFixedArray();
$array->{0} = new X();
var_dump($array);
// As of php 8.3, get_mangled_object_vars only contains object properties (dynamic properties and declared subclass properties)
// (Array elements in the SplFixedArray are deliberately excluded)
// Before php 8.3, this would have array elements get removed in some cases but not others.
var_dump(get_mangled_object_vars($array));
echo "cast to array\n";
var_dump((array)$array); // Adds the values from the underlying array, then the declared/dynamic object properties
echo json_encode($array), "\n"; // From JsonSerializable::serialize()
$ser = serialize($array);
echo "$ser\n";
// NOTE: The unserialize behavior for the property that is the string '0' is just because unserialize()
// is coercing '0' to a string before calling SplFixedArray::__unserialize.
//
// Typical code would not use 0 as a property name, this test is just testing edge cases have proper reference counting and so on.
var_dump(unserialize($ser));
?>
--EXPECT--
array(1) {
["x"]=>
NULL
}
object(MySplFixedArray)#1 (4) {
[0]=>
object(stdClass)#2 (0) {
}
[1]=>
object(Y)#3 (0) {
}
["x"]=>
object(SplFixedArray)#4 (0) {
}
["0"]=>
object(X)#5 (0) {
}
}
array(2) {
["x"]=>
object(SplFixedArray)#4 (0) {
}
[0]=>
object(X)#5 (0) {
}
}
cast to array
array(3) {
[0]=>
object(X)#5 (0) {
}
[1]=>
object(Y)#3 (0) {
}
["x"]=>
object(SplFixedArray)#4 (0) {
}
}
[{},{}]
O:15:"MySplFixedArray":4:{i:0;O:8:"stdClass":0:{}i:1;O:1:"Y":0:{}s:1:"x";O:13:"SplFixedArray":0:{}s:1:"0";O:1:"X":0:{}}
object(MySplFixedArray)#6 (3) {
[0]=>
object(X)#10 (0) {
}
[1]=>
object(Y)#8 (0) {
}
["x"]=>
object(SplFixedArray)#9 (0) {
}
}