You are here: lambda inside of lambda? « PHP Programming Language « IT news, forums, messages
lambda inside of lambda?

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]


Удаленная работа для программистов  •  Как заработать на 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

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