]> granicus.if.org Git - php/commitdiff
Adding regression test for behavior of magic methods with unset public properties
authorMarco Pivetta <ocramius@gmail.com>
Fri, 26 Oct 2012 01:54:05 +0000 (03:54 +0200)
committerLars Strojny <lstrojny@php.net>
Sun, 2 Dec 2012 18:47:09 +0000 (19:47 +0100)
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>
tests/classes/unset_public_properties.phpt [new file with mode: 0644]

diff --git a/tests/classes/unset_public_properties.phpt b/tests/classes/unset_public_properties.phpt
new file mode 100644 (file)
index 0000000..8c0096e
--- /dev/null
@@ -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