xref: /php-src/Zend/tests/bug63462.phpt (revision 902d6439)
1--TEST--
2Test script to verify that magic methods should be called only once when accessing an unset property.
3--CREDITS--
4Marco Pivetta <ocramius@gmail.com>
5--FILE--
6<?php
7#[AllowDynamicProperties]
8class Test {
9    public    $publicProperty;
10    protected $protectedProperty;
11    private   $privateProperty;
12
13    public function __construct() {
14        unset(
15            $this->publicProperty,
16            $this->protectedProperty,
17            $this->privateProperty
18        );
19    }
20
21    function __get($name) {
22        echo '__get ' . $name . "\n";
23        return $this->$name;
24    }
25
26    function __set($name, $value) {
27        echo '__set ' . $name . "\n";
28        $this->$name = $value;
29    }
30
31    function __isset($name) {
32        echo '__isset ' . $name . "\n";
33        return isset($this->$name);
34    }
35}
36
37$test = new Test();
38
39$test->nonExisting;
40$test->publicProperty;
41$test->protectedProperty;
42$test->privateProperty;
43isset($test->nonExisting);
44isset($test->publicProperty);
45isset($test->protectedProperty);
46isset($test->privateProperty);
47$test->nonExisting       = 'value';
48$test->publicProperty	 = 'value';
49$test->protectedProperty = 'value';
50$test->privateProperty   = 'value';
51
52?>
53--EXPECTF--
54__get nonExisting
55
56Warning: Undefined property: Test::$nonExisting in %s on line %d
57__get publicProperty
58
59Warning: Undefined property: Test::$publicProperty in %s on line %d
60__get protectedProperty
61
62Warning: Undefined property: Test::$protectedProperty in %s on line %d
63__get privateProperty
64
65Warning: Undefined property: Test::$privateProperty in %s on line %d
66__isset nonExisting
67__isset publicProperty
68__isset protectedProperty
69__isset privateProperty
70__set nonExisting
71__set publicProperty
72__set protectedProperty
73__set privateProperty
74