Re: [PATCH] [RFC] Closures and lambda functions in PHP

From: Date: Fri, 27 Jun 2008 19:46:45 +0000
Subject: Re: [PATCH] [RFC] Closures and lambda functions in PHP
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-38662@lists.php.net to get a copy of this message
On Friday 27 June 2008, Dmitry Stogov wrote: > 1) Fixed ref/noref issues Works for me. See attached test 11. Gesundheit Wag -- For sale: baby shoes, never worn. - flash fiction by Hemingway

--TEST-- Closure test: Closure calls itself --SKIPIF-- <?php if (!class_exists('Closure')) die('skip Closure support is needed'); ?> --FILE-- <?php $i = 3; $lambda = function ($lambda) use (&$i) { if ($i==0) return; echo $i--."\n"; $lambda($lambda); }; $lambda($lambda); echo "$i\n"; ?> --EXPECT-- 3 2 1 0 --TEST-- Closure test: Lexical copies not static in closure --SKIPIF-- <?php if (!class_exists('Closure')) die('skip Closure support is needed'); ?> --FILE-- <?php $i = 1; $lambda = function () use ($i) { return ++$i; }; $lambda(); echo $lambda()."\n"; //early prototypes gave 3 here because $i was static in $lambda ?> --EXPECT-- 2
« previous php.internals (#38662) next »