In other languages, saw something similar

function help(array name) { echo '1'; } function help(string name) { echo '2'; } help(array('Васек', 'Петруха')); //выведет 1 help('Клавчиха'); //выведет 2 

those. the type of function transferred depends on the function call

Is there such a thing in php and how to implement it?

    3 answers 3

    PHP does not support function overloading; it is also not possible to override or delete a function declared earlier.

    Php.net source

    • Well, how fatalistic something. After all, you can fight and find a solution. - istem
    • @istem, the solution is in response to @zloctb, but this is not an overload. - ReinRaus
    • The classic solution is to pass an array ParameterName => Value. It works quite effectively, but formally it is not an overload. - SilverIce

    And if you use func_get_args and, depending on the passed argument, bring it to the desired type and return the desired result.

      But what if you try stupidly like this:

       <? function help ($arg) { if (is_array($arg)) echo "1"; elseif (is_string($arg)) echo "2"; elseif (is_int($arg)) echo "3"; else echo "5"; }