Posted by Oli Filth on 10/27/65 11:26
Peter Salzman said the following on 10/09/2005 17:21:
> Hi all,
>
> Since PHP is a (weakly) typed language, is it possible to overload functions
> based on the type of their argument?
No. But there are default arguments, and variable-length argument lists
(PHP 4+).
See http://www.php.net/manual/functions.arguments.php.
> Also, are there function pointers in PHP?
No. But there are functions like call_user_func(), which make them
somewhat redundant.
See http://www.php.net/call_user_func.
>
> Here's why I'm asking. Consider these two function:
>
>
> function foo( $arg ) { echo "foo $arg foo\n"; }
>
> function bar() { echo "barfoo"; }
>
>
> I'd like to be able to do this:
>
> foo('hello');
> foo(&bar());
>
> to produce this:
>
> foo hello foo
> foo barfoo foo
>
How about:
function foo($arg)
{
echo "foo $arg foo\n";
}
function bar()
{
return "barfoo";
}
foo(bar());
--
Oli
[Back to original message]
|