You are here: Passing a function & arguments to a function « PHP « IT news, forums, messages
Passing a function & arguments to a function

Posted by David Johnson on 09/28/58 11:18

I am trying to pass a function as an argument to another function, and
then run the first function from within the second function.

Example:

function function0($arg0, $arg1, $arg2) {

function2();

}

function function1($arg3, $arg4, $arg5) {

function3();
do_function($arg5);
function4();

}


function1(5, 100, function0($arg0, $arg1, $arg2));




In the above example, I am running function1(), which includes
function0 as an argument.

I am trying to pass "function0($arg0, $arg1, $arg2)" as an argument to
function1, which will then execute the passed function, including its
passed arguments.

I have had mild success by splitting "function0($arg0, $arg1, $arg2)"
into 2 parts of "function0" and "$arg0, $arg1, $arg2", and then
passing both parts as an argument, such as $arg5 & $arg6, and then
doing this:

function function1($arg3, $arg4, $arg5) {

$args_array = explode(", ",$arg6);
$arg5($args_array[0],$args_array[1],$args_array[2]);

}



However, this causes all of my arguments in the array to be evaluated
as strings and not resources, which they may be.

Also, I don't really like this method, and would prefer a much
"cleaner" way of doing things.

 

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

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