You are here: Re: address of functions « PHP Programming Language « IT news, forums, messages
Re: address of functions

Posted by Richard on 02/20/07 22:31

Rik <luiheidsgoeroe@hotmail.com> writes:

> On Tue, 20 Feb 2007 22:53:14 +0100, Richard <rgrdev@gmail.com> wrote:
>
>>
>> Is it possible to store the address or reference to a function in
>> php? Maybe
>> using just a string and later dereferencing it?
>>
>> e.g some ideas to illustrate what I mean
>>
>> <?php
>> function myCompanyMotto(){
>> echo "hello";
>> }
>>
>> $myarr["func1"]=&myCompanyMotto;
>> $myarr["func2"]="myCompanyMotto";
>>
>> //how to get function from myarr and call it????
>>
>> ?>
>
> I'd just use call_user_func()/call_user_func_array(), and save the
> callback either as a string for normal functions, and as an array for
> object/class methods.
>
> function myCompanyMotto(){
> echo "hello";
> }
> class foo{
> function bar(){
> echo 'class';
> }
> }
> $myarr['func1'] = 'myCompanyMotto';
> $myarr['func2'] = array('foo','bar');
> call_user_func($myarr['func1']);
> call_user_func($myarr['func2']);

Thanks, I had googled, but being new to PHP I hadnt found
call_user_func. Just what I want.

 

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

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