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

Posted by gosha bine on 08/17/07 06:35

Chad Yoshikawa wrote:
> 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======================================
>

Looks like a php bug to me. Lambdas' names start with the nul symbol
(\x00) and create_function seems to handle that incorrectly.

A test case

$a = "foo \x00";
var_dump($a);
var_dump(eval("return '$a';"));
$f = create_function('', "return '$a';");

I would report this.


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

 

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

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