note 91326 deleted from language.oop5.overloading by cmb
| From: | cmb@php.net | Date: | Sun, 18 Aug 2019 08:30:27 +0000 |
| Subject: | note 91326 deleted from language.oop5.overloading by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211906@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
It is possible to accomplish method polymorphism via PHP's __call method:
<?php
class Example{
public function __call($name, $arguments){
switch($name){
case 'foo':
switch(count($arguments)){
case 2:
echo 'You called "foo" with two arguments.<br>' .
PHP_EOL;
break;
case 3:
echo 'You called "foo" with three arguments.<br>'
. PHP_EOL;
break;
default:
echo 'Error: Invalid number of arguments to
"foo."<br>' . PHP_EOL;
break;
}
break;
default:
echo "Error: Call to undefined function \"$name.\"<br>" .
PHP_EOL;
}
}
}
$test = new Example;
$test->foo('bar', 'baz');
$test->foo('bar', 'baz', 'fez', 'fap');
$test->bar();
?>