You are here: Re: How to pass a function to a function?, and how to pass the variables of the function? « All PHP « IT news, forums, messages
Re: How to pass a function to a function?, and how to pass the variables of the function?

Posted by Fabian Hore on 10/13/08 11:27

just realised my previous comment is misleading.

1.
You CAN pass the function name as a String.
e.g; f_example("f");
- so when $function_to_execute contains a string you CAN do
$function_to_execute()

2.
You SHOULDN'T try and treat the function as an object
e.g; f_example(f);
- PHP will assume that f is a constant, i.e NOT a function object.


However using an undeclared constant like this will default to a string, so
#2 above will still work, but an E_NOTICE error will be raised plus it's
just bad form.


I digress.





"Chris Hope" <blackhole@electrictoolbox.com> wrote in message
news:dh0aro$qhl$1@lust.ihug.co.nz...
> _andrea.l wrote:
>
>> I'd like to write a function like:
>>
>> function f(){ ... bla ...}
>> f_example(f);
>>
>> function f_example($function_to_execute)
>> {...bla... $function_to_execute() ...bla....}
>>
>> AND how to pass the variable of the function :
>>
>> function f_example($function_to_execute($var1,$var2))
>> {...bla... $function_to_execute() ...bla....}
>>
>> Thank you in advance for the time you'll spend for me,
>> Andrea.
>
> This should get you going in the right direction:
> http://www.php.net/manual/en/function.call-user-func-array.php
>
> --
> Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

 

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

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