flush
[mdref/mdref-propro] / php / PropertyProxy / __construct.md
1 # void php\PropertyProxy::__construct(mixed &$object, string $member[, php\PropertyProxy $parent = NLL])
2
3 Create a new property proxy for the property $member of $object.
4
5 ## Params:
6
7 * mixed reference &$object
8 The storage from which to reference the property.
9 * string $member
10 The name of the property to reference.
11 * php\PropertyProxy $parent = NULL
12 Any parent property proxy.
13
14 ## Example:
15
16 class c {
17 private $storage = array();
18 function __get($p) {
19 return new php\PropertyProxy($this->storage, $p);
20 }
21 function __set($p, $v) {
22 $this->storage[$p] = $v;
23 }
24 }
25
26 $c = new c;
27 $c->data["foo"] = 1;
28
29 var_dump($c);
30
31 $c->data[] = 1;
32 $c->data[] = 2;
33 $c->data[] = 3;
34 $c->data["bar"][] = 123;
35 $c->data["bar"][] = 456;
36
37 var_dump($c);
38 unset($c->data["bar"][0]);
39
40 var_dump($c);
41
42 Yields:
43
44 object(c)#1 (1) {
45 ["storage":"c":private]=>
46 array(1) {
47 ["data"]=>
48 array(1) {
49 ["foo"]=>
50 int(1)
51 }
52 }
53 }
54 object(c)#1 (1) {
55 ["storage":"c":private]=>
56 array(1) {
57 ["data"]=>
58 array(5) {
59 ["foo"]=>
60 int(1)
61 [0]=>
62 int(1)
63 [1]=>
64 int(2)
65 [2]=>
66 int(3)
67 ["bar"]=>
68 array(2) {
69 [0]=>
70 int(123)
71 [1]=>
72 int(456)
73 }
74 }
75 }
76 }
77 object(c)#1 (1) {
78 ["storage":"c":private]=>
79 array(1) {
80 ["data"]=>
81 array(5) {
82 ["foo"]=>
83 int(1)
84 [0]=>
85 int(1)
86 [1]=>
87 int(2)
88 [2]=>
89 int(3)
90 ["bar"]=>
91 array(1) {
92 [1]=>
93 int(456)
94 }
95 }
96 }
97 }