summaryrefslogtreecommitdiff
path: root/tests/classes/__set__get_005.phpt
blob: 298c8b1e11a2c45d88ed30b2d152129d76197aee (plain)
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
--TEST--
ZE2 __set() and __get()
--FILE--
<?php
class Test
{
    protected $x;

    function __get($name) {
        echo __METHOD__ . "\n";
        if (isset($this->x[$name])) {
            return $this->x[$name];
        }
        else
        {
            return NULL;
        }
    }

    function __set($name, $val) {
        echo __METHOD__ . "\n";
        $this->x[$name] = $val;
    }
}

class AutoGen
{
    protected $x;

    function __get($name) {
        echo __METHOD__ . "\n";
        if (!isset($this->x[$name])) {
            $this->x[$name] = new Test();
        }
        return $this->x[$name];
    }

    function __set($name, $val) {
        echo __METHOD__ . "\n";
        $this->x[$name] = $val;
    }
}

$foo = new AutoGen();
$foo->bar->baz = "Check";

var_dump($foo->bar);
var_dump($foo->bar->baz);

?>
--EXPECTF--
AutoGen::__get
Test::__set
AutoGen::__get
object(Test)#%d (1) {
  ["x":protected]=>
  array(1) {
    ["baz"]=>
    string(5) "Check"
  }
}
AutoGen::__get
Test::__get
string(5) "Check"