You are here: Re: Overloaded functions and function pointers in PHP? « PHP Programming Language « IT news, forums, messages
Re: Overloaded functions and function pointers in PHP?

Posted by Oli Filth on 11/06/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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация