summaryrefslogtreecommitdiff
path: root/Zend/tests/property_access_errors_for_guarded_properties.phpt
blob: 0a360a9447d756bd55b903d2c72568c61a3ffd33 (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
--TEST--
Property access errors should be thrown for overloaded properties protected by recursion guards
--FILE--
<?php

function setProp($obj) {
    $obj->prop = 42;
}

function getProp($obj) {
    var_dump($obj->prop);
}

function unsetProp($obj) {
    unset($obj->prop);
}

class Test {
    private $prop;

    public function __get($k) {
        getProp($this);
    }

    public function __set($k, $v) {
        setProp($this);
    }

    public function __unset($k) {
        unsetProp($this);
    }
}

$test = new Test;
try {
    $test->prop = "bar";
} catch (Error $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump($test->prop);
} catch (Error $e) {
    echo $e->getMessage(), "\n";
}
try {
    unset($test->prop);
} catch (Error $e) {
    echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Cannot access private property Test::$prop
Cannot access private property Test::$prop
Cannot access private property Test::$prop