xref: /PHP-8.2/tests/classes/__set__get_004.phpt (revision f8d79582)
1--TEST--
2ZE2 __set() and __get()
3--FILE--
4<?php
5class Test {
6    protected $x;
7
8    function __get($name) {
9        if (isset($this->x[$name])) {
10            return $this->x[$name];
11        }
12        else
13        {
14            return NULL;
15        }
16    }
17
18    function __set($name, $val) {
19        $this->x[$name] = $val;
20    }
21}
22
23$foo = new Test();
24$bar = new Test();
25$bar->baz = "Check";
26
27$foo->bar = $bar;
28
29var_dump($bar->baz);
30var_dump($foo->bar->baz);
31
32?>
33--EXPECT--
34string(5) "Check"
35string(5) "Check"
36