xref: /PHP-8.3/ext/spl/tests/array_022.phpt (revision f8d79582)
1--TEST--
2SPL: ArrayObject/Iterator and reference to self
3--FILE--
4==ArrayObject===
5<?php
6
7class MyArrayObject extends ArrayObject
8{
9    public function __construct()
10    {
11        parent::__construct($this);
12        $this['bar'] = 'baz';
13    }
14}
15
16$a = new MyArrayObject;
17
18$b = clone $a;
19$b['baz'] = 'Foo';
20
21var_dump($a);
22var_dump($b);
23
24?>
25==ArrayIterator===
26<?php
27
28class MyArrayIterator extends ArrayIterator
29{
30    public function __construct()
31    {
32        parent::__construct($this);
33        $this['bar'] = 'baz';
34    }
35}
36
37$a = new MyArrayIterator;
38
39$b = clone $a;
40$b['baz'] = 'Foo';
41
42var_dump($a);
43var_dump($b);
44
45?>
46--EXPECTF--
47==ArrayObject===
48object(MyArrayObject)#%d (1) {
49  ["bar"]=>
50  string(3) "baz"
51}
52object(MyArrayObject)#%d (2) {
53  ["bar"]=>
54  string(3) "baz"
55  ["baz"]=>
56  string(3) "Foo"
57}
58==ArrayIterator===
59object(MyArrayIterator)#%d (1) {
60  ["bar"]=>
61  string(3) "baz"
62}
63object(MyArrayIterator)#%d (2) {
64  ["bar"]=>
65  string(3) "baz"
66  ["baz"]=>
67  string(3) "Foo"
68}
69