Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62599 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41622 invoked from network); 30 Aug 2012 14:04:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2012 14:04:34 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:33777] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/32-29476-0F27F305 for ; Thu, 30 Aug 2012 10:04:33 -0400 Received: by lbbgp3 with SMTP id gp3so525278lbb.29 for ; Thu, 30 Aug 2012 07:04:29 -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=ala6efM07n8+LfoNayeYl92tKoLYqYHlq3OA0VQwCeA=; b=bYh2/CtmoLI0mGrCvLXNb/aVVMbeNTfYATwNuSuHuVm6Ql6WsuCPzXg51btiYU9eND EM4NI22egTrbqQZlUFikHMLvPDpBiNQuHaonff6PW4ZOa3golV1KEcDm+8OICXPA0T+B bhKoRjcKbqYwhTnYgnABujWT3ruJSHOzU2/qTaYNIEYWKwytDYOnnRbVRVJj1I06Kqgq wd7qXDB1+AUEvT6kTwcTS8jgh1dGatiCQQh+J8npaMzdouOc/1Re7eIk6EhmNxWPNCII paC5sabRxIXjLjxtOBMq/6pRBV86v8HBijrX/VbMOa8izsxWjGUGCouWZqsYQPCZ5Rxt 40XQ== MIME-Version: 1.0 Received: by 10.152.144.168 with SMTP id sn8mr3452813lab.1.1346335469063; Thu, 30 Aug 2012 07:04:29 -0700 (PDT) Received: by 10.152.108.145 with HTTP; Thu, 30 Aug 2012 07:04:28 -0700 (PDT) In-Reply-To: References: <20120829162147.QQCM24459.aamtaout04-winn.ispmail.ntl.com@p2> <503E7FF1.40607@sugarcrm.com> Date: Thu, 30 Aug 2012 16:04:28 +0200 Message-ID: To: Derick Rethans Cc: Stas Malyshev , Hannes Magnusson , Jared Williams , PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [VOTE] Generators From: nikita.ppv@gmail.com (Nikita Popov) On Thu, Aug 30, 2012 at 10:27 AM, Derick Rethans wrote: > On Wed, 29 Aug 2012, Stas Malyshev wrote: > >> >> 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?! >> >> I'd rather have it skip foreach, maybe producing a warning/notice. >> It'd otherwise also be only place generators throw exceptions, which >> is a bit unexpected. > > Indeed. Even though yield/generator is an iterator *internally*, > nothing on the language syntax side hints at that. Nothing even > indicates you're using "OO" there. > > This is unlike the SplIterators where are you are clearly constructing > fancy objects. In their most trivial use (i.e. just sticking them into foreach) you won't notice that generator objects are actually, well, objects. But still you can work with them as objects and they also expose the Iterator API. E.g. you can call $gen->rewind() and this will throw an Exception (if it isn't rewindable at the moment). Do you disagree that this should throw an exception? Should it throw an error instead? If not, then why would the same rewind() call done internally in foreach not also throw an Exception? Why would that throw an error instead? It's two times the same thing, just invoked slightly different. Nikita