|
Posted by Chad Yoshikawa on 08/17/07 04:26
I'm trying to use create_function to create a new function with a
function body which calls a lambda function, but with no luck.
I get an "unexpected $end" parser error. Is this possible, or do I
need to use some other approach?
Here is sample code which generates the error. The first part works,
the second part does not:
===============cut here======================================
<?php
function test($a,$b) {
if ($a==$b) return 0; return ($a<$b)?-1:1;
}
function outer($a,$b,$innerfunctionname) {
return $innerfunctionname($a,$b);
}
$innerfunction = create_function('$a,$b','if ($a==$b) return 0; return
($a<$b)?-1:1;');
########First Part#############
#This works - prints -1
$outerfunction1 = create_function('$a,$b', "return outer(\$a,\
$b,'test');");
$result1 = $outerfunction1(3,4);
printf("Result1 is %d\n",$result1);
#######Second Part############
#This doesn't work -- prints "PHP Parse error: syntax error,
unexpected $end in /tmp/test.php(22) : runtime-created function on
line 1"
$outerfunction2 = create_function('$a,$b', "return outer(\$a,\
$b,'$innerfunction');");
$result2 = $outerfunction2(3,4);
printf("Result2 is %d\n",$result2);
?>
===============cut here======================================
Navigation:
[Reply to this message]
|