com php-src: Adding regression test for behavior of magic methods with unset public properties: tests/classes/unset_public_propert ies.phpt
| From: | Lars Strojny | Date: | Sun, 02 Dec 2012 18:47:09 +0000 |
| Subject: | com php-src: Adding regression test for behavior of magic methods with unset public properties: tests/classes/unset_public_propert ies.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-70641@lists.php.net to get a copy of this message | ||
Commit: 1377942b6963f53c77226b8a68832183b9916426
Author: Marco Pivetta <ocramius@gmail.com> Fri, 26 Oct 2012 03:54:05 +0200
Committer: Lars Strojny <lstrojny@php.net> Sun, 2 Dec 2012 19:47:09 +0100
Parents: 12de2e91d0f10f93e177378f84d1dcc1c03e1141
Branches: PHP-5.4
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1377942b6963f53c77226b8a68832183b9916426
Log:
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>
Changed paths:
A tests/classes/unset_public_properties.phpt
Diff:
diff --git a/tests/classes/unset_public_properties.phpt b/tests/classes/unset_public_properties.phpt
new file mode 100644
index 0000000..8c0096e
--- /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