note 104110 added to language.oop5.overloading

From: Date: Mon, 23 May 2011 23:15:46 +0000
Subject: note 104110 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-179991@lists.php.net to get a copy of this message
Be careful of __call in case you have a protected/private method. Doing this: <?php class TestMagicCallMethod { public function foo() { echo __METHOD__.PHP_EOL; } public function __call($method, $args) { echo __METHOD__.PHP_EOL; if(method_exists($this, $method)) { $this->$method(); } } protected function bar() { echo __METHOD__.PHP_EOL; } private function baz() { echo __METHOD__.PHP_EOL; } } $test = new TestMagicCallMethod(); $test->foo(); /** * Outputs: * TestMagicCallMethod::foo */ $test->bar(); /** * Outputs: * TestMagicCallMethod::__call * TestMagicCallMethod::bar */ $test->baz(); /** * Outputs: * TestMagicCallMethod::__call * TestMagicCallMethod::baz */ ?> ..is probably not what you should be doing. Always make sure that the methods you call in __call are allowed as you probably dont want all the private/protected methods to be accessed by a typo or something. ---- Server IP: 69.147.83.197 Probable Submitter: 203.143.235.178 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/104110 Del: integrated -- https://master.php.net/note/delete/104110/integrated Del: useless -- https://master.php.net/note/delete/104110/useless Del: bad code -- https://master.php.net/note/delete/104110/bad+code Del: spam -- https://master.php.net/note/delete/104110/spam Del: non-english -- https://master.php.net/note/delete/104110/non-english Del: in docs -- https://master.php.net/note/delete/104110/in+docs Del: other reasons-- https://master.php.net/note/delete/104110 Reject -- https://master.php.net/note/reject/104110 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179991) next »