note 111907 deleted from language.oop5.overloading by aharvey
| From: | aharvey@php.net | Date: | Thu, 11 Apr 2013 00:04:43 +0000 |
| Subject: | note 111907 deleted from language.oop5.overloading by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194441@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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.