xref: /PHP-8.3/ext/spl/tests/array_003.phpt (revision 902d6439)
1--TEST--
2SPL: ArrayObject from object
3--FILE--
4<?php
5
6// This test also needs to exclude the protected and private variables
7// since they cannot be accessed from the external object which iterates
8// them.
9
10#[AllowDynamicProperties]
11class test
12{
13    public    $pub = "public";
14    protected $pro = "protected";
15    private   $pri = "private";
16
17    function __construct()
18    {
19        $this->imp = "implicit";
20    }
21};
22
23$test = new test;
24$test->dyn = "dynamic";
25
26print_r($test);
27
28$object = new ArrayObject($test);
29
30print_r($object);
31
32foreach($test as $key => $val)
33{
34    echo "$key => $val\n";
35}
36
37?>
38--EXPECT--
39test Object
40(
41    [pub] => public
42    [pro:protected] => protected
43    [pri:test:private] => private
44    [imp] => implicit
45    [dyn] => dynamic
46)
47ArrayObject Object
48(
49    [storage:ArrayObject:private] => test Object
50        (
51            [pub] => public
52            [pro:protected] => protected
53            [pri:test:private] => private
54            [imp] => implicit
55            [dyn] => dynamic
56        )
57
58)
59pub => public
60imp => implicit
61dyn => dynamic
62