From 1377942b6963f53c77226b8a68832183b9916426 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 26 Oct 2012 03:54:05 +0200 Subject: Adding regression test for behavior of magic methods with unset public properties Verifies that after having unset a public property, any access to it, be it read or write, causes calls to public magic methods Signed-off-by: Marco Pivetta --- tests/classes/unset_public_properties.phpt | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/classes/unset_public_properties.phpt diff --git a/tests/classes/unset_public_properties.phpt b/tests/classes/unset_public_properties.phpt new file mode 100644 index 0000000000..8c0096ee41 --- /dev/null +++ b/tests/classes/unset_public_properties.phpt @@ -0,0 +1,74 @@ +--TEST-- +Un-setting public instance properties causes magic methods to be called when trying to access them from outside class scope +--FILE-- +$name = $value; + echo '__set ' . $name . ' to ' . $value; + } + + public function __isset($name) + { + echo '__isset ' . $name; + return isset($this->$name); + } + + public function getTestProperty() + { + return $this->testProperty; + } + + public function setTestProperty($testProperty) + { + $this->testProperty = $testProperty; + } +} + +$o = new Test; + +echo $o->testProperty; +echo "\n"; +isset($o->testProperty); +echo "\n"; +unset($o->testProperty); +isset($o->testProperty); +echo "\n"; +echo $o->testProperty; +echo "\n"; +echo $o->getTestProperty(); +echo "\n"; +echo $o->setTestProperty('new value via setter'); +echo "\n"; +echo $o->testProperty; +echo "\n"; +unset($o->testProperty); +$o->testProperty = 'new value via public access'; +echo "\n"; +isset($o->testProperty); +echo "\n"; +echo $o->testProperty; + +?> +====DONE==== +--EXPECTF-- +property set + +__isset testProperty +__get testProperty +__get testProperty +__set testProperty to new value via setter +new value via setter +__set testProperty to new value via public access + +new value via public access -- cgit v1.2.1