|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-11-17 08:24 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 06:00:01 2025 UTC |
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!