Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102331 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93056 invoked from network); 20 Jun 2018 16:40:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2018 16:40:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 84.19.169.162 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 84.19.169.162 mail.experimentalworks.net Received: from [84.19.169.162] ([84.19.169.162:34770] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/87-32156-8838A2B5 for ; Wed, 20 Jun 2018 12:40:40 -0400 Received: from kuechenschabe.fritz.box (ppp-188-174-114-173.dynamic.mnet-online.de [188.174.114.173]) by mail.experimentalworks.net (Postfix) with ESMTPSA id 7FE8843184; Wed, 20 Jun 2018 18:40:37 +0200 (CEST) Message-ID: <1529512836.2713.59.camel@schlueters.de> To: Michael Moravec , internals@lists.php.net Date: Wed, 20 Jun 2018 18:40:36 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC][Discussion] iterable_to_array() and iterable_count() From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Mi, 2018-06-20 at 03:55 +0200, Michael Moravec wrote: > Hello internals, > > I'd like to propose two new functions for PHP 7.3: > iterable_to_array() and > iterable_count() > > These functions are supposed to work with iterables (7.1 pseudotype) > - both arrays and iterators, unlike iterator_*() functions which only > work with iterators. > Is there any reason not to extend the existing functions to also allow arrays? 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. johannes