Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62588 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78512 invoked from network); 29 Aug 2012 21:50:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Aug 2012 21:50:16 -0000 Authentication-Results: pb1.pair.com header.from=hannes.magnusson@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=hannes.magnusson@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: hannes.magnusson@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:44231] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/53-59480-79E8E305 for ; Wed, 29 Aug 2012 17:50:15 -0400 Received: by vcbgb30 with SMTP id gb30so1300325vcb.29 for ; Wed, 29 Aug 2012 14:50:13 -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=aiXWr1QOEwhkpteGD+6ro4NawTMhoIpDDMHoHt1GAt0=; b=0kbYZ12ejPmYSiUTN4vkUxhWs7r8+LTBZapPfjrXFRDQhSpf490bVuAMs3C1ylNS69 KrW7BlHRltBuwieryAhEQ4gaUz7nTXpI12pJuSRHXN4ndHxAo8DTMkeejoXYD80aQnuS M1q8MNPZ9TfaKEbEH07o1jzIDYi44VYfxPLbDcdJPBy40zDPj9t/Qt98++/hOD7LrYfb IscxeHq72QIAG4S1Jm+3e6TgLqKQs68B56WkmykrUS4pJCPH54r+aSej6gTUEGLuhEVx bBt86Y2wi4j3PlHLca5bdKShfaHMe7xMgelxGfN+TT9X9ACI98w38sNx78Wr1YV6pz0w uAiw== MIME-Version: 1.0 Received: by 10.52.71.137 with SMTP id v9mr1586652vdu.63.1346277012965; Wed, 29 Aug 2012 14:50:12 -0700 (PDT) Received: by 10.58.196.169 with HTTP; Wed, 29 Aug 2012 14:50:12 -0700 (PDT) In-Reply-To: References: <20120829162147.QQCM24459.aamtaout04-winn.ispmail.ntl.com@p2> Date: Wed, 29 Aug 2012 22:50:12 +0100 Message-ID: To: Derick Rethans Cc: Nikita Popov , Jared Williams , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [VOTE] Generators From: hannes.magnusson@gmail.com (Hannes Magnusson) On Wed, Aug 29, 2012 at 10:19 PM, Derick Rethans wrote: > On Wed, 29 Aug 2012, Nikita Popov wrote: > >> On Wed, Aug 29, 2012 at 10:10 PM, Derick Rethans wrote: >> > On Wed, 29 Aug 2012, Nikita Popov wrote: >> > >> >> > function &bind(array $keys, array &$row) >> >> > { >> >> > foreach($keys as $key) >> >> > yield $key => $row[$key]; >> >> > } >> >> > >> >> > $row = []; >> >> > $it = bind(['a', 'b'], $row); >> >> > >> >> > foreach($it as $key => &$ref) >> >> > echo $key; >> >> > echo "\n"; >> >> > foreach($it as $key => &$ref) >> >> > echo $key; >> >> >> >> Thanks, this is now fixed. It'll throw an exception now, saying that >> >> you can't traverse an already closed generator. >> > >> > Nothing in the core throws an exception, why would this?! >> >> To my knowledge all iterator-related functionality is supposed to >> throw exceptions (as it is a feature related to the object oriented >> part of PHP). At leas this is what a quick search of the code base >> gave me. (See http://lxr.php.net/xref/PHP_TRUNK/ext/spl/spl_dllist.c#1248 >> for example). > > "ext/spl" - SPL is not *core* language. The generators are. Don't throw > exceptions from core features! In general I agree with core language features shouldn't be throwing exceptions... But SPL definitely should never have been its own extension and most of it should have been core language features - and throwing exceptions in many of those cases makes perfect sense. We also have the case of IteratorAggregate throwing exception (which is a *core* language feature, not defined in ext/spl): $ ./sapi/cli/php -r 'class foo implements IteratorAggregate { function getIterator() { return new stdclass; } } foreach(new foo as $bar) {}' Fatal error: Uncaught exception 'Exception' with message 'Objects returned by foo::getIterator() must be traversable or implement interface Iterator' in Command line code:1 Stack trace: #0 Command line code(1): unknown() #1 {main} thrown in Command line code on line 1 -Hannes