Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77394 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56158 invoked from network); 20 Sep 2014 22:06:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Sep 2014 22:06:27 -0000 Authentication-Results: pb1.pair.com header.from=leight@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=leight@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.176 as permitted sender) X-PHP-List-Original-Sender: leight@gmail.com X-Host-Fingerprint: 74.125.82.176 mail-we0-f176.google.com Received: from [74.125.82.176] ([74.125.82.176:36371] helo=mail-we0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/10-55126-36AFD145 for ; Sat, 20 Sep 2014 18:06:27 -0400 Received: by mail-we0-f176.google.com with SMTP id w61so382290wes.35 for ; Sat, 20 Sep 2014 15:06:24 -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=EPkAka4wx0GTMmOw6PyPJDoe0Zip38DWRZjo8q4Fz0k=; b=lzVAcETbnLYprRa/z7peeVvJjYw0iW0HGB3hLhN4KIzqT6NaKZPGSIHBQPeZcwZa6P zp7BnMA9QET5/AFLPnI+t9G6iFZamixPTxb1uoZg2HIoeYG9fJWQxmH1Xpr8euysP00k W08QXcAAwsBpb49MOTMQfhMfcO3VFD9iqguyHjqL4VGm7hZD+Sv/pYOOsow8ENZr8yB5 1fy5NuHjUPQbL5SKT+jYRWJn5b9U9BiY1btdf/pO4YkjtZScDFGpbE0RS1YGm3zCaTLY cnqdu4wskFrAQqEN3cxPYDY90QbRirUn9rIfY17kY2m0Qip13hNuYMaxy6E/yz9wWqzb vYpQ== MIME-Version: 1.0 X-Received: by 10.180.86.73 with SMTP id n9mr5445136wiz.30.1411250784320; Sat, 20 Sep 2014 15:06:24 -0700 (PDT) Received: by 10.217.55.195 with HTTP; Sat, 20 Sep 2014 15:06:24 -0700 (PDT) In-Reply-To: <1A5B2D07-FEC6-410E-85C9-3FBE2F105104@golemon.com> References: <1A5B2D07-FEC6-410E-85C9-3FBE2F105104@golemon.com> Date: Sat, 20 Sep 2014 23:06:24 +0100 Message-ID: To: Sara Golemon Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Loop... or... From: leight@gmail.com (Leigh) On 20 September 2014 20:47, Sara Golemon wrote: > > I like the general idea, but rather than explicitly focusing on the 'or' keyword, how about just giving all loop constructs (do/while/for/foreach) a return value? I'd suggest an integer return value indicating the number of times the loop executed. > > This accomodates your use case since foreach(...) {} or { defaultblock } still works, while also allowing for others: > > e.g.: > $ranTwice = foreach(...) {} == 2; > > It does introduce a temp var, but OpCache+ can trivially optimize that out when it isn't used. > > -Sara Sorry @Sara - didn't reply to all the first time. ---- mind === blown This would open up a huge amount of other functionality I'd never dreamed of (some of which is quite scary!) for($i = for(...) {}; $i < ...) {} I'm really not sure I understand the full implication of this though. This would mean changing loop constructs from statements to expressions. I wonder how difficult that will actually be, and what other problems it would cause (I obviously haven't played with this idea yet). It would also mean having to make { default block } into an expression... with a return value (to be allowed on either side of the boolean or) Lots to think about here, if it's at all viable this will need it's own separate RFC, it's a much more invasive change, but definitely a great idea.