Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62092 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69167 invoked from network); 9 Aug 2012 02:50:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2012 02:50:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:48488] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/90-00812-A5523205 for ; Wed, 08 Aug 2012 22:50:04 -0400 Received: by lahl5 with SMTP id l5so518800lah.29 for ; Wed, 08 Aug 2012 19:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=N9oVYefv+NuM6JBc8PS+h4a8NxPghiKoPzthibVzn8Q=; b=jV3/cfVLFkSprdYFMmEuwKcr7da6+0bUiBz0FT52oY0X6SDzw74wUEL7Svg75WgO0l dzdZH+lXivefRNWCFKs8AeWugf3S2e1+tHCA4ED4vmcQB7p9kd0/oR4DAvdN6aQAf6lb KOfmq3zEd3GwBCLlMcOaRXHpgE26LuY+t6friui6qphAwKfoDfkWKDNYOV/VQ85ixKB7 lNVsLzMkwJwigL2Wgu+zBZN0MQZUM75JFY/oLDwJj5WVsI6Ud8xCs38RJblVcGq4SxP4 bFtbEUmUmRkcQToE5i75LOqFkRoAFQq8+7h6zFIILe+S2o0dbFo+x5CY42/DbJ/mzOvs wv8w== MIME-Version: 1.0 Received: by 10.152.102.234 with SMTP id fr10mr2342980lab.32.1344480599559; Wed, 08 Aug 2012 19:49:59 -0700 (PDT) Received: by 10.112.8.7 with HTTP; Wed, 8 Aug 2012 19:49:59 -0700 (PDT) In-Reply-To: <50231FAD.40104@garfieldtech.com> References: <500EE3B9.8010902@ajf.me> <500EEA76.1030407@ajf.me> <5010138D.5050804@ajf.me> <501015B9.6050704@ajf.me> <501058B9.5050004@lsces.co.uk> <501249B6.5070507@lsces.co.uk> <50128825.4020902@lsces.co.uk> <50231FAD.40104@garfieldtech.com> Date: Wed, 8 Aug 2012 22:49:59 -0400 Message-ID: To: Larry Garfield Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Re: Generators in PHP From: theanomaly.is@gmail.com (Sherif Ramadan) > > One question, though: It looks based on the voting like finally {} blocks > are going in. So... what should happen in the following situation: > > function stuff() { > try { > foreach (range(1, 100) as $i) { > yield $i; > } > } > finally { > print "All done"; > } > } > > Does "All done" get printed once, or 101 times? Similarly: > > function things() { > $i = 1; > try { > while (true) { > yield $i++; > } > } > finally { > print "All done"; > } > } > > That will run indefinitely. So will "All done" ever print, or does that > finally become unreachable? > > (I have no clue what the behavior "should" be in these cases, just that it > should be sorted out sooner rather than later.) > Based on my understanding of both RFCs, I don't see that this would be a conflict or lead to unexpected behavior. As stated by the generators RFC: "When you first call the generator function ($lines = getLinesFromFile($fileName)) the passed argument is bound, but nothing of the code is actually executed. Instead the function directly returns a Generator object.". So in the event we are calling the function stuff(), nothing should actually be executed, and as we iterate over the traversable object the generator should be "passing control back and forth between the generator and the calling code". This would be indicated by the "yield" keyword present in the function. Meaning you should see the expected result and finally should only ever be called once in your first example. As for you second example... Obviously if you've created an infinite loop you've made everything outside of the loop unreachable, whether you're using generators or not. However, I'll let the author of the RFC provide any clarification or corrections where I might be wrong.