#35252 [Opn->Bgs]: __get not called if parameter exists
| From: | derick@php.net | Date: | Thu, 17 Nov 2005 07:24:57 +0000 |
| Subject: | #35252 [Opn->Bgs]: __get not called if parameter exists | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-88338@lists.php.net to get a copy of this message | ||
ID: 35252
Updated by: derick@php.net
Reported By: php at seven dot net dot nz
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Win XP
PHP Version: 5CVS-2005-11-17 (CVS)
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is how it should work. __get() and __set() only work on non-set
properties.
Previous Comments:
------------------------------------------------------------------------
[2005-11-17 04:55:10] php at seven dot net dot nz
Description:
------------
When overloading a class, the __get magic function is not called if the
parameter in question has been set on the object. I'm not sure if this
is by design, but it seems to defeat the purpose of it somewhat.
Reproduce code:
---------------
<?php
class Cat {
public function __get ($variable) {
if (method_exists ($this, "get_$variable"))
return $this->{"get_$variable"} ();
elseif (isset ($this->$variable))
return $this->$variable;
else
throw new Exception ("$variable not found");
}
public function get_noise () {
return "Meow!";
}
}
$test = new Cat;
print $test->noise."\n";
$test->noise = "Woof!";
print $test->noise."\n";
print $test->get_noise ()."\n";
print $test->__get ("noise")."\n";
?>
Expected result:
----------------
Meow!
Meow!
Meow!
Meow!
Actual result:
--------------
Meow!
Woof!
Meow!
Meow!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35252&edit=1