<?php
class Test
{
public function __call($name, $args)
{
$method = $name.'_'.join('_', array_map('gettype', $args));
if(method_exists($this, $method))
{
return call_user_func_array([$this, $method], $args);
}
}
protected function foo_int_string($x, $y)
{
echo('Called method implementation with 1-st (int) and 2-nd (string) parameters'.PHP_EOL);
}
protected function foo_int_int($x, $y)
{
echo('Called method implementation with 1-st (int) and 2-nd (int) parameters'.PHP_EOL);
}
}
$obj=new Test();
$obj->foo(5, "bar");
$obj->foo(8, 2);
preferences:
38.46 ms | 402 KiB | 5 Q