Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102552 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35627 invoked from network); 2 Jul 2018 02:14:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jul 2018 02:14:28 -0000 Authentication-Results: pb1.pair.com header.from=mail@majkl578.cz; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=mail@majkl578.cz; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain majkl578.cz designates 209.85.128.170 as permitted sender) X-PHP-List-Original-Sender: mail@majkl578.cz X-Host-Fingerprint: 209.85.128.170 mail-wr0-f170.google.com Received: from [209.85.128.170] ([209.85.128.170:38378] helo=mail-wr0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/A9-15351-18A893B5 for ; Sun, 01 Jul 2018 22:14:27 -0400 Received: by mail-wr0-f170.google.com with SMTP id j33-v6so988029wrj.5 for ; Sun, 01 Jul 2018 19:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=majkl578.cz; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=7kIT1FyFuLuAMmZtkGq7+ZhtCiVXKtdPUY6Fe/kFdeg=; b=l28PkhfRyN2Va6e2C9qvttWSH53z5s77JP/xWkp/Q6ofaq7A/0x/kmnHk1QcRb5Edp lPrnsdecdXndzk14N5Q9N6rxnDB9LugBOlMjRxPvZn4t0+u96sSLNWWkaT6M3D3bj05O XsSC6CJjnKt+0BMElk33YiJmmonUir3imQLKdU94hP4e7u3lR2YI9+nwqgPcmh1Lsm6D psZC69QT87cK1e4udXH406/q3RGweN0nXGkRUdDfPR4UT+ipP7N36j6oRhis73pzgKLK oTdiH1amlH9uBp1icYaPZxLj1+fcUhuaSRy2kaD0kUObc2Z/KCyZS8ymPn5fRR/DABjE Svbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=7kIT1FyFuLuAMmZtkGq7+ZhtCiVXKtdPUY6Fe/kFdeg=; b=em0sCUKltGhA3LunbHuYVc6a6gnxCl1IOa/uAoGxzkt9E4W+HVkyfUwrbcWEHTvvNI I/e5XBnZuGS/JY5F3YMrYVCj8JI1OYKbms56k0cnDyRtWSV2a6Y7vfrGcaVQcaAkRlz2 Ue/vTZ8ZFWuu6SHyk4IjG2kB+jPaWeLcso9alWSMvMRZKBhfae/jujrt9tjKYqdrRwTh D67VGZwWOcl5Mk+6ABaLBCRuAGpKJtORl97jX2ZXoR/4c0SCoTr1JaS3kHKRR92zzWX5 cmjst8PI+Lgi8Wiw7F0LAftKJmMUzjNsSZQ+4TnlU2Hfw7VHVw11LD9Hd+5JNL1wmVG2 7ABQ== X-Gm-Message-State: APt69E2/2Zhme3F9WXcCiaVMa7IGe4mim8f+zmbEMJYbQvEegc06/0/s T6fgZx3n+D94Mng7aWCAGHUFjdk+3YJbrZsbP+T0UPyc X-Google-Smtp-Source: AAOMgpdWVE8w2NBGwHogrE56/cwzebJE3WxH2MZ/BfIQITSKH9ccTnt1UrjhmkLG7FdkZnowRndIxd6Fg8utridHsdE= X-Received: by 2002:adf:bbc9:: with SMTP id z9-v6mr18000143wrg.183.1530497663077; Sun, 01 Jul 2018 19:14:23 -0700 (PDT) MIME-Version: 1.0 Sender: mail@majkl578.cz Received: by 2002:a5d:570f:0:0:0:0:0 with HTTP; Sun, 1 Jul 2018 19:14:02 -0700 (PDT) X-Originating-IP: [2a02:8308:33d:7400:4417:9097:83b0:4e23] In-Reply-To: <1529512836.2713.59.camel@schlueters.de> References: <1529512836.2713.59.camel@schlueters.de> Date: Mon, 2 Jul 2018 04:14:02 +0200 X-Google-Sender-Auth: lWTVoCmQhO10KsvB9_rNeoRPeCo Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Michael Moravec , internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000089a583056ffac16c" Subject: Re: [PHP-DEV] [RFC][Discussion] iterable_to_array() and iterable_count() From: php.net@majkl578.cz (Michael Moravec) --00000000000089a583056ffac16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Johannes, 2018-06-20 18:40 GMT+02:00 Johannes Schl=C3=BCter : > > Is there any reason not to extend the existing functions to also allow > arrays? > Yes, this was discussed in the PR on GitHub: https://github.com/php/php-src/pull/3293#issuecomment-397082988 There are two main reasons to not do that: 1) Naming: iterator_*(), as the name suggests, is supposed to work with iterators. Making it work with arrays would be highly confusing. 2) Not altering/reusing existing functions: Changing behavior of existing functions that exist for many years is also confusing for consumers. In both cases this would make code harder to understand (i.e. taking versio= n of PHP into efffect). > Also for the count one: Mind that iterator_count()/iterable_count() > doesn't respect the Countable interface and consumes the iterator, > which might not be resetable. A slightly better choice might be > > (is_array($iterable) || implements_countable($iterable)) ? > count($iterable) : iterator_count($iterable) > > And even then I would put a warning sign against blindly using it on > any iterator. > Just like with existing iterator_count(), this is up to the consumer to decide whether it's safe or not to use (especially with generators). It has exactl= y the same benefits and drawbacks. Also I'm not sure whether this is a downside of *_count() or not, IMHO it's designed specifically to count an iterator that is not Countable. So for an iterable, one may prefer: is_countable($value) ? count($value) : iterable_count($value) But again, this is up to the consumer to decide whether it's safe or not. johannes > Thanks, Michael --00000000000089a583056ffac16c--