#35252 [NEW]: __get not called if parameter exists

From: Date: Thu, 17 Nov 2005 03:55:11 +0000
Subject: #35252 [NEW]: __get not called if parameter exists
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-88332@lists.php.net to get a copy of this message
From: php at seven dot net dot nz Operating system: Win XP PHP version: 5CVS-2005-11-17 (CVS) PHP Bug Type: Class/Object related Bug description: __get not called if parameter exists 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 bug report at http://bugs.php.net/?id=35252&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35252&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35252&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35252&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=35252&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35252&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35252&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35252&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35252&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35252&r=support Expected behavior: http://bugs.php.net/fix.php?id=35252&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35252&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35252&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35252&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35252&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35252&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35252&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35252&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35252&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35252&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35252&r=mysqlcfg

« previous php.bugs (#88332) next »