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