Repository navigation
Expand file tree
/
Copy pathgh10519.phpt
More file actions
72 lines (62 loc) · 1.75 KB
/
Copy pathgh10519.phpt
File metadata and controls
72 lines (62 loc) · 1.75 KB
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
--TEST--
Bug GH-10519 (Array Data Address Reference Issue)
--XFAIL--
The fix for this was bad
--FILE--
<?php
interface DataInterface extends JsonSerializable, RecursiveIterator, Iterator
{
public static function init(Traversable $data): DataInterface;
}
class A extends RecursiveArrayIterator implements DataInterface
{
public function __construct($data)
{
parent::__construct($data);
}
public static function init($data): DataInterface
{
return new static($data);
}
public function getCols(string $colname): array
{
return array_column($this->getArrayCopy(), $colname);
}
public function bugySetMethod($key, $value)
{
$data = &$this;
while ($data->hasChildren()) {
$data = $data->getChildren();
}
$data->offsetSet($key, $value);
}
public function jsonSerialize(): mixed
{
return $this;
}
}
$a = [
'test' => [
'a' => (object) [2 => '',3 => '',4 => ''],
]
];
$example = A::init($a);
$example->bugySetMethod(5, 'in here');
var_dump(json_encode($example));
var_dump(json_encode($a));
$b = [
'test' => [
'b' => [2 => '',3 => '',4 => ''],
]
];
$example = A::init($b);
$example->bugySetMethod(5, 'must be here');
var_dump(json_encode($example));
var_dump(json_encode($b));
?>
--EXPECTF--
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
string(51) "{"test":{"a":{"2":"","3":"","4":"","5":"in here"}}}"
string(51) "{"test":{"a":{"2":"","3":"","4":"","5":"in here"}}}"
string(56) "{"test":{"b":{"2":"","3":"","4":"","5":"must be here"}}}"
string(37) "{"test":{"b":{"2":"","3":"","4":""}}}"