summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Pivetta <ocramius@gmail.com>2012-10-26 03:54:05 +0200
committerLars Strojny <lstrojny@php.net>2012-12-02 19:47:09 +0100
commit1377942b6963f53c77226b8a68832183b9916426 (patch)
tree82f127b7b5a1e5bad2750af1b7b80122b1cfaf22
parent12de2e91d0f10f93e177378f84d1dcc1c03e1141 (diff)
downloadphp-git-1377942b6963f53c77226b8a68832183b9916426.tar.gz
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 <ocramius@gmail.com>
-rw-r--r--tests/classes/unset_public_properties.phpt74
1 files changed, 74 insertions, 0 deletions
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--
+<?php
+
+class Test
+{
+ public $testProperty = 'property set';
+
+ public function __get($name)
+ {
+ return '__get ' . $name;
+ }
+
+ public function __set($name, $value)
+ {
+ $this->$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