xref: /PHP-8.1/ext/spl/tests/array_003.phpt (revision f8d79582)
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
10class test
11{
12    public    $pub = "public";
13    protected $pro = "protected";
14    private   $pri = "private";
15
16    function __construct()
17    {
18        $this->imp = "implicit";
19    }
20};
21
22$test = new test;
23$test->dyn = "dynamic";
24
25print_r($test);
26
27$object = new ArrayObject($test);
28
29print_r($object);
30
31foreach($test as $key => $val)
32{
33    echo "$key => $val\n";
34}
35
36?>
37--EXPECT--
38test Object
39(
40    [pub] => public
41    [pro:protected] => protected
42    [pri:test:private] => private
43    [imp] => implicit
44    [dyn] => dynamic
45)
46ArrayObject Object
47(
48    [storage:ArrayObject:private] => test Object
49        (
50            [pub] => public
51            [pro:protected] => protected
52            [pri:test:private] => private
53            [imp] => implicit
54            [dyn] => dynamic
55        )
56
57)
58pub => public
59imp => implicit
60dyn => dynamic
61