For example, lets say I have:
Code: Select all
callfunction($something)
{
dofunction($foo, $bar, $etc);
}Any ideas?
Moderator: General Moderators
Code: Select all
callfunction($something)
{
dofunction($foo, $bar, $etc);
}*playing stupid* then why are you calling it?Roja wrote:Because we don't know what dofunction() takes.nielsene wrote:Why not pass an array to both?
Code: Select all
$var="rumMe";
$foo->$var();When you call callfunction(), it gets the correct number of functions.nielsene wrote: Honestly if you don't know what arguments a function takes, how can you call it?
Infinite. Unknown.nielsene wrote: you would need to set up a calling convention for the possible functions that $var could be.
Not really. Its completely unavoidable, and I simply need that solution. Nothing else outside the problem can fix the problem I face.nielsene wrote:I'm having a hard time picturing why you're in the situation you're in. Can you offer any more details?
Code: Select all
$in = 1;
$out = 7;
callfunction($in, $out);
function callfunction($something)
{
$numargs = func_num_args();
$args = '';
if( $numargs > 1 )
{
$arg_list = func_get_args();
for($i=0;$i<$numargs;$i++)
{
$args .= $arg_list[$i];
if($i != $numargs-1)
{
$args .= ', ';
}
}
}
echo "args are: " . $args; // output is "1, 7".
echo add($args); // This in theory should result in 8. In fact, it gets the error "missing arg 2".
}
function add($in, $out)
{
$new = $in+$out;
return $new;
}Code: Select all
#!/usr/local/php/bin/php
<?php
function add($a,$b) {
return $a+$b;
}
function do_call($func,$args) {
$numargs = count($args);
$arg_string = "";
for ($i=0;$i<$numargs;$i++) {
if ($i!=0) $arg_string.=", ";
$arg_string.=$args[$i];
}
$callString ="\$ret={$func}($arg_string);";
echo $callString;
eval($callString);
echo $ret;
}
$in=1;
$out=7;
$args=array($in,$out);
echo do_call("add",$args);
?>Code: Select all
echo "args are: " . $args; // output is "1, 7".
echo add($args); // This in theory should result in 8. In fact, it gets the error "missing arg 2".Code: Select all
#!/usr/local/php/bin/php
<?php
function add($a,$b) {
return $a+$b;
}
function do_call($func,$args) {
$ret = call_user_func_array($func,$args);
echo $ret;
}
$in=1;
$out=7;
$args=array($in,$out);
echo do_call("add",$args);
?>Code: Select all
$in = 1;
$out = 7;
callfunction($in, $out);
function callfunction($something)
{
$arg_list = func_get_args();
echo call_user_func_array('add', $arg_list);
}
function add($in, $out)
{
$new = $in+$out;
return $new;
}