Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62739 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69269 invoked from network); 3 Sep 2012 13:12:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Sep 2012 13:12:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:50876] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 21/C9-20751-1DCA4405 for ; Mon, 03 Sep 2012 09:12:50 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 03AFD70003F8; Mon, 3 Sep 2012 14:12:47 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id FoEF-kWL4C8j; Mon, 3 Sep 2012 14:12:46 +0100 (WEST) Received: from nebm.ist.utl.pt (unknown [IPv6:2001:690:2100:4::58:1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 59AA870003DD; Mon, 3 Sep 2012 14:12:46 +0100 (WEST) Received: from localhost ([127.0.0.1] helo=nebm.ist.utl.pt) by nebm.ist.utl.pt with esmtp (Exim 4.72) (envelope-from ) id 1T8WSM-0001ki-8A; Mon, 03 Sep 2012 14:12:46 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 03 Sep 2012 15:12:46 +0200 To: Derick Rethans Cc: Rasmus Lerdorf , Pierre Joye , Stas Malyshev , PHP Internals Organization: =?UTF-8?Q?N=C3=BAcleo_de_Engenharia_Biom=C3=A9dica_do_Insti?= =?UTF-8?Q?tuto_Superior_T=C3=A9cnico?= In-Reply-To: References: <5040DC47.8000305@ajf.me> <5040F4D9.80206@sugarcrm.com> <5042946A.80204@sugarcrm.com> <5042A7D6.7050001@lerdorf.com> Message-ID: X-Sender: glopes@nebm.ist.utl.pt User-Agent: RoundCube Webmail/0.8-rc Subject: Re: [PHP-DEV] Re: Are exceptions allowed in php =?UTF-8?Q?core=3F?= From: glopes@nebm.ist.utl.pt (Gustavo Lopes) Em 2012-09-03 13:16, Derick Rethans escreveu: >> I think the first thing anyone who uses generators must understand >> is that >> they are iterators. > > You forget that not even everybody that uses PHP knows what an > iterator > is. For all they care, they have an array they can run foreach() on. > >> They should be compared with iterators, not arrays. > > They shouldn't be compared with either. They are magical things that > happen with a "yield" keyword. OK, you prefer to replace the facts (generators are iterator objects and they are introduced as such) with an alternative reality that putatively exists (or will exist) in the users' mind. I have no interest in a discussion in those terms, especially (1) without any evidence indicating such mental model is widespread and (2) given that the exceptions you claim to be surprising don't happen but for a programming error (i.e. they're not exceptions that need to be caught). >> With that in mind, the behavior is not surprising for anyone who >> knows >> how iterators and foreach interact. >> >> More importantly, there is no other satisfactory solution (except a >> fatal >> error). foreach has no return value, so it has no other way to >> signal a >> failure. If we used a notice or a warning here what would happen is >> that code >> that used generators with an invalid state would, except for the >> notice, work >> as if it had been given an empty iterator. Put another way, it would >> fail with >> only a notice, and continue. > > Continue doing what? > I've replied here: http://www.mail-archive.com/internals@lists.php.net/msg60706.html -- Gustavo Lopes