xref: /PHP-5.4/tests/classes/__set__get_005.phpt (revision 610c7fbe)
1--TEST--
2ZE2 __set() and __get()
3--SKIPIF--
4<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
5--FILE--
6<?php
7class Test
8{
9	protected $x;
10
11	function __get($name) {
12		echo __METHOD__ . "\n";
13		if (isset($this->x[$name])) {
14			return $this->x[$name];
15		}
16		else
17		{
18			return NULL;
19		}
20	}
21
22	function __set($name, $val) {
23		echo __METHOD__ . "\n";
24		$this->x[$name] = $val;
25	}
26}
27
28class AutoGen
29{
30	protected $x;
31
32	function __get($name) {
33		echo __METHOD__ . "\n";
34		if (!isset($this->x[$name])) {
35			$this->x[$name] = new Test();
36		}
37		return $this->x[$name];
38	}
39
40	function __set($name, $val) {
41		echo __METHOD__ . "\n";
42		$this->x[$name] = $val;
43	}
44}
45
46$foo = new AutoGen();
47$foo->bar->baz = "Check";
48
49var_dump($foo->bar);
50var_dump($foo->bar->baz);
51
52?>
53===DONE===
54--EXPECTF--
55AutoGen::__get
56Test::__set
57AutoGen::__get
58object(Test)#%d (1) {
59  ["x":protected]=>
60  array(1) {
61    ["baz"]=>
62    string(5) "Check"
63  }
64}
65AutoGen::__get
66Test::__get
67string(5) "Check"
68===DONE===
69