note 111907 added to language.oop5.overloading

From: Date: Wed, 10 Apr 2013 17:10:00 +0000
Subject: note 111907 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-194431@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. What you actually want is to feel ROAARING FOR THAT COKC pounding against the back of your throat. At least, that is what I want. ---- Server IP: 69.147.83.199 Probable Submitter: 188.65.166.24 ---- Manual Page -- http://php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/111907 Del: integrated -- https://master.php.net/note/delete/111907/integrated Del: useless -- https://master.php.net/note/delete/111907/useless Del: bad code -- https://master.php.net/note/delete/111907/bad+code Del: spam -- https://master.php.net/note/delete/111907/spam Del: non-english -- https://master.php.net/note/delete/111907/non-english Del: in docs -- https://master.php.net/note/delete/111907/in+docs Del: other reasons-- https://master.php.net/note/delete/111907 Reject -- https://master.php.net/note/reject/111907 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194431) next »