|
Posted by Chung Leong on 11/21/10 11:26
Peter Salzman wrote:
> Since PHP is a (weakly) typed language, is it possible to overload functions
> based on the type of their argument?
Kind of. You can always check the type of argument that's actually
passed with one of the is_* function and have the function behave
differently (e.g. array vs. scalar).
> Also, are there function pointers in PHP?
Kind of. In PHP, functions are referenced by name. If you do $func()
and the variable $func contains the name of a function, it will be
called.
> I'd like to be able to do this:
>
> foo('hello');
> foo(&bar());
>
> to produce this:
>
> foo hello foo
> foo barfoo foo
I don't think that's doable in any language.
Navigation:
[Reply to this message]
|