Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99715 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53454 invoked from network); 3 Jul 2017 16:09:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jul 2017 16:09:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.214.51 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.214.51 mail-it0-f51.google.com Received: from [209.85.214.51] ([209.85.214.51:37640] helo=mail-it0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/15-15131-22C6A595 for ; Mon, 03 Jul 2017 12:09:07 -0400 Received: by mail-it0-f51.google.com with SMTP id m84so58846227ita.0 for ; Mon, 03 Jul 2017 09:09:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=UQuvTZaSxxFWhGD6PgkItrKY8TgBSTSQnGh5gdOrz14=; b=TJX2kthdjlMsy60b0zWmdSH6o5G5VMcphwmybIZNeLCNum+1XB7LdPWmkY6h1iU9rv ta6ZJnZQiM5TYt23DWCbl4jHTBm75NfhN7KxfOHPWfgs6O1+YHplN1m73+DERFkRp0f3 fLfBTEtcR6RBticXGheaR8VpfzuYxlGNr4Va4c8g7rE2yo4WuEx7xyhlB3sF1xKJFBsL /zl6vQ8mGllz66uIp7R6Y3PEJhyPAfIITWzUJQmrKNHp6UUCRJf7SmBPo5r0X6qXuB24 Bd3q/c4r+bqSNeG94ucor+yjoHHkVA/ndGxFCIZzMxqaU8dOnU1875ILe/rWGW4GocER VHIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=UQuvTZaSxxFWhGD6PgkItrKY8TgBSTSQnGh5gdOrz14=; b=MW6ey9MCKfS5jkVcMEW+eMRiDWjvwaCuMwhVuknjchCok5OJdK/2aiMatlPHyvJsnQ I89CKLXOsmNGGZ4vHXzIjPuYiq6PslCV7ZO6j2V7v/LCMWKinmg1ufi6I6afmaFzrzQo h2Hjmz+Wf6ziraS1kBwdXrifxY+91O9aiTLhTDdYqqFN2be9CMMNVkU5tiDoNZiDgqmK OdCeX0APz/6SSqE1oUx4v4YQNJLtIltQCtnlYw8ZJqvbvklhSoc818l4HHX5p+MqmV1d yLkRoDCsbHqUq//apVMJYoaHyRvlQTiLo0v/FcPXg3Ve3StQeP3o3XKNYhgbfozrm7i3 ShbA== X-Gm-Message-State: AIVw1101+Ot1uD7Xxb4drCjC5w5V6Mb6slQGuRzhNU7+EUFSRmlwlh1W MYK5pgP82Wlp9DLe9dY= X-Received: by 10.36.50.199 with SMTP id j190mr9392403ita.110.1499098143392; Mon, 03 Jul 2017 09:09:03 -0700 (PDT) Received: from mail-io0-f171.google.com (mail-io0-f171.google.com. [209.85.223.171]) by smtp.googlemail.com with ESMTPSA id u78sm2268844ita.12.2017.07.03.09.09.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jul 2017 09:09:02 -0700 (PDT) Received: by mail-io0-f171.google.com with SMTP id h64so59012854iod.0 for ; Mon, 03 Jul 2017 09:09:02 -0700 (PDT) X-Received: by 10.107.154.5 with SMTP id c5mr39170027ioe.109.1499098142536; Mon, 03 Jul 2017 09:09:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.246.71 with HTTP; Mon, 3 Jul 2017 09:08:42 -0700 (PDT) In-Reply-To: <1499097219.19635.57.camel@schlueters.de> References: <1499095625.19635.52.camel@schlueters.de> <1499097219.19635.57.camel@schlueters.de> Date: Mon, 3 Jul 2017 18:08:42 +0200 X-Gmail-Original-Message-ID: Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Niklas Keller , PHP Internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] "Reader" as alternative to Iterator From: andreas@dqxtech.net (Andreas Hennings) On Mon, Jul 3, 2017 at 5:53 PM, Johannes Schl=C3=BCter wrote: > On Mo, 2017-07-03 at 17:32 +0200, Niklas Keller wrote: > >> > That distinction is the reason why next() and valid() are different >> > methods in iterators. I would rather say this is the reason why current() and valid() are different methods. A combination of ->current() and next() would not cause problems. >> >> Not really, Iterator::next() returns void, so could as well return >> bool. > > Well, that story is a bit longer and I cut it short. Let's assume we > remove valid and use next's return value. Then we don't know if the > first element exists or not, as next is only called after the first > iteration. An alternative might be using only current() but then we > need a special, magic, return value to mark the end oder references. > Both are bad. The proposed ->read() method is more or less the same as ->current() plus ->next(), if ->current() always returns FALSE on end-of-data. An object that has both ->read() and ->valid() would remove the need for a special magic return value. But in many many cases, having a magic return value FALSE is totally accept= able. Think of fgetcsv(), fread(), or PDOStatement::fetch(). So if we wanted, we could have one interface "SimpleReader" or "FalseTerminatedReader" with only the ->read() method, and another method "Reader" with both ->read() and ->valid(). (Sometimes I would like to have a new data type "unique symbol" for constants that are not strings or integers. So we could say "while (EOF !=3D=3D $value =3D $reader->read());" but this is another topic) > > johannes