Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62152 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35818 invoked from network); 14 Aug 2012 17:59:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Aug 2012 17:59:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=aaron@aaronholmes.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=aaron@aaronholmes.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain aaronholmes.net from 209.85.160.170 cause and error) X-PHP-List-Original-Sender: aaron@aaronholmes.net X-Host-Fingerprint: 209.85.160.170 mail-gh0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:64561] helo=mail-gh0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/00-00812-CE19A205 for ; Tue, 14 Aug 2012 13:59:11 -0400 Received: by ghbg24 with SMTP id g24so841726ghb.29 for ; Tue, 14 Aug 2012 10:59:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=plldgMzEbNRD23hK+8c3vysfBwZwYIlQxZrKwKz0hXc=; b=eSNG5m3oSc+eVsMLIq1TD7aB7heoDYDwCvu0P8FAzQHAoV/PwTZDsLlMNlX71uaQxn 0AR7wxt/bcCZFdyrnrP5r0+IZuZAMelY398BLz+2Z5Q3X+mAY1pJUxuO3ZHaD3eGd7sy wErlFybgSkOQJOLv1S86sVVDAGkCaU9NUZ9qWTRswTLayuE6N760cIHHORj2/fsf6EDP zlEClwY7yiHhTI3a09YMrbpjYgUSSlJPfahBu11ABCunm7C0gs7RomnKQ/bophd2PBUf +j3MIIo8c2rZn5QoqktGivhKt8hKWLtqBOFB3NG0d5lA0AWMzVPZyLML/dFI/ob/+wKB A7rQ== Received: by 10.50.222.162 with SMTP id qn2mr13281990igc.46.1344967146229; Tue, 14 Aug 2012 10:59:06 -0700 (PDT) Received: from aaronh-macbook.local ([38.122.108.2]) by mx.google.com with ESMTPS id hi1sm10973921igc.13.2012.08.14.10.59.04 (version=SSLv3 cipher=OTHER); Tue, 14 Aug 2012 10:59:05 -0700 (PDT) Message-ID: <502A91E7.4030204@aaronholmes.net> Date: Tue, 14 Aug 2012 10:59:03 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Stas Malyshev CC: "internals@lists.php.net" References: <50280D37.10109@moonspot.net> <502A7FFB.1090502@aaronholmes.net> <502A8CB2.7060708@sugarcrm.com> In-Reply-To: <502A8CB2.7060708@sugarcrm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnqhwiJU3GzRmqcMZBYFqFV+INubLtw206yYVWNxn+n0Cytn21qWgu8nE8OKhi/azcopah3 Subject: Re: [PHP-DEV] [RFC] Generators From: aaron@aaronholmes.net (Aaron Holmes) On 8/14/12 10:36 AM, Stas Malyshev wrote: > Hi! > >> That said, rewind() should behave consistently. I don't feel it makes >> sense to have rewind() succeed at one point, and fail at another. It >> would only cause confusion when not familiar with the behavior. Either >> allow it, or don't. Not both. > It does, since foreach uses rewind. So first rewind should succeed if > you want iterators be usable in foreach. OTOH, on something like DB > result set, next rewind does not make any sense, if you have > non-seekable cursor, since the results consumed are gone and there's no > way to get them back (you could rerun the query, but it might have side > effects and nobody guarantees you'd get the same result anyway). So it > makes sense for the generator to succeed on first rewind but fail on > next ones. Note that generators by nature are stateful objects, so it is > not unexpected that they would produce different result in different > states. > Thanks for clarifying. It makes sense now, considering foreach's behavior and the generators statefulness allowing what otherwise seems inconsistent. However, might it make sense to no-op instead of erroring? If generators allow rewind(), it would be unexpected to receive an error for calling it.