Since many here probably wanted to do ?real? overloading without having to think too much, here's a generic __call() function for those cases.
Little example :
<?php
class OverloadedClass {
public function __call($f, $p) {
if (method_exists($this, $f.sizeof($p))) return call_user_func_array(array($this, $f.sizeof($p)), $p);
throw new Exception('Tried to call unknown method '.get_class($this).'::'.$f);
}
function Param2($a, $b) {
echo "Param2($a,$b)\n";
}
function Param3($a, $b, $c) {
echo "Param3($a,$b,$c)\n";
}
}
$o = new OverloadedClass();
$o->Param(4,5);
$o->Param(4,5,6);
$o->ParamX(4,5,6,7);
?>
Will output :
Param2(4,5)
Param3(4,5,6)
Fatal error: Uncaught exception 'Exception' with message 'Tried to call unknown method OverloadedClass::ParamX' in overload.php:7
Stack trace:
#0 [internal function]: OverloadedClass->__call('ParamX', Array)
#1 overload.php(22): OverloadedClass->ParamX(4, 5, 6, 7)
#2 {main}
thrown in overload.php on line 7