No, this is impossible to do, as you might expect.
From manual :
PHP does not support function overloading, nor is it possible to define or override previously declared functions.
HOWEVER, you can use runkit_function_redefine and its cousins, but it is definitely not very elegant ...
You can also use create_function to do something like this:
<?php $func = create_function('$a,$b','return $a + $b;'); echo $func(3,5); // 8 $func = create_function('$a,$b','return $a * $b;'); echo $func(3,5); // 15 ?>
Like runkit, it is not very elegant, but it gives the behavior you are looking for.
Paolo Bergantino Feb 10 '09 at 0:25 2009-02-10 00:25
source share