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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
--TEST--
property proxy
--SKIPIF--
<?php if (!extension_loaded("propro")) print "skip"; ?>
--FILE--
<?php
echo "Test\n";
class c {
private $storage = array();
function __get($p) {
$pp = new php\PropertyProxy(null, $p,
new php\PropertyProxy($this, "storage"));
return $pp;
}
function __set($p, $v) {
$this->storage[$p] = $v;
}
}
$c = new c;
$c->data["foo"] = 1;
var_dump(
isset($c->data["foo"]),
isset($c->data["bar"])
);
var_dump($c);
$c->data[] = 1;
$c->data[] = 2;
$c->data[] = 3;
$c->data["bar"][] = 123;
$c->data["bar"][] = 456;
var_dump($c);
unset($c->data["bar"][0]);
var_dump($c);
?>
DONE
--EXPECTF--
Test
bool(true)
bool(false)
object(c)#%d (1) {
["storage":"c":private]=>
array(1) {
["data"]=>
array(1) {
["foo"]=>
int(1)
}
}
}
object(c)#%d (1) {
["storage":"c":private]=>
array(1) {
["data"]=>
array(5) {
["foo"]=>
int(1)
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
["bar"]=>
array(2) {
[0]=>
int(123)
[1]=>
int(456)
}
}
}
}
object(c)#%d (1) {
["storage":"c":private]=>
array(1) {
["data"]=>
array(5) {
["foo"]=>
int(1)
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
["bar"]=>
array(1) {
[1]=>
int(456)
}
}
}
}
DONE
|