Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102621 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28143 invoked from network); 5 Jul 2018 20:59:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2018 20:59:02 -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 74.125.82.48 as permitted sender) X-PHP-List-Original-Sender: mail@majkl578.cz X-Host-Fingerprint: 74.125.82.48 mail-wm0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:35646] helo=mail-wm0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/58-55607-5968E3B5 for ; Thu, 05 Jul 2018 16:59:01 -0400 Received: by mail-wm0-f48.google.com with SMTP id v3-v6so8963920wmh.0 for ; Thu, 05 Jul 2018 13:59:01 -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=Yi40WtRPe8ezyNpt3jaZwBIeUcEUjj65aghU9li/oG4=; b=iRxOfnyljjUwpOkxmdjVRtxnfwRs/BzI6+wF5KxLSqcXHrOMiPTXKC6UtSk0FfPUKF xsGrqw2WzxeSMY0dPaaN7S+qiGe3bpuqyQ74UUCzB1clrKP7VEjgt6Qjbb5pPVDxpW1C xgnO6Bfodw8ZPF2ue2r91+gbpiMNdXZl29hb2FCGUchPCAmLhNRN/STHIVfrXZoQmWgk AwFFpRTsBuaPR/Se8Mug/m9DM/SJkduY15AusaulV43QTkQWlg7uvN1O9Q+fAYexu31/ V5tb5W1A+OX5Aw+L+eFjMphn2aTW1JBMlgWCLB0loF7Epl78DoDznyeb1pvYxuOkW4op sTjA== 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=Yi40WtRPe8ezyNpt3jaZwBIeUcEUjj65aghU9li/oG4=; b=J5aZEf3YNbc+qK57hQqhm4IB6wkKY1W10L78TefT7XLmZsSkGmfHlNJWg0NaqtgepA JQ/hcjDb4dsPUXsOA/tkY4wsFL5qZ2fN34SGlVmBWNLtRj4cTaRkJYuPMMvIMjKg8e2M pGj2ssx33rkwsVf6SUVHKZLj627y2HmgIF2ueGEQwsK8yz/6Dvv76hgnNTFzyY8mOc7m hPGTX1nLergKl67HfgqkXOiVI9rQ2jWr29jqbe73Szj+OqFVGRrK4SlR9RY5WQKYqGXR JJuMkx6e2BYhINANKQL+V99kKaByViw904RXHlCQ3gR32/rx11atEyKwzcvN3Xe6GvCp KZaQ== X-Gm-Message-State: APt69E11hLBL62hLE02piFeG2XWhDi/oWg1fjm3MDhuALSevL6ktlpFu cOjcHG+ja5uyZHqekFH3GpgoZ5blHM3gvXprByVcKRdu5F8= X-Google-Smtp-Source: AAOMgpdpbaOOiCTftM3mUxLSl/6UgjunfFEW+zO0UUWeQl+z/5ovl3Mr7jS/8pIzx8TM449gcPErnTLSxovXP+x/NEY= X-Received: by 2002:a1c:3b54:: with SMTP id i81-v6mr5162727wma.143.1530824338068; Thu, 05 Jul 2018 13:58:58 -0700 (PDT) MIME-Version: 1.0 Sender: mail@majkl578.cz Received: by 2002:a5d:570f:0:0:0:0:0 with HTTP; Thu, 5 Jul 2018 13:58:37 -0700 (PDT) X-Originating-IP: [2a00:1028:9190:d232:ad90:d725:f4c0:fa05] In-Reply-To: References: Date: Thu, 5 Jul 2018 22:58:37 +0200 X-Google-Sender-Auth: eD7yZyNT5ghEor4CD7a9vi3HDC8 Message-ID: To: Nikita Popov Cc: Michael Moravec , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC][Vote] iterable_to_array() and iterable_count() From: php.net@majkl578.cz (Michael Moravec) 2018-07-05 22:35 GMT+02:00 Nikita Popov : > I voted against both functions. Jordi already explained why iterable_count() > is questionable, so let me add a comment regarding iterable_to_array(). > > Essentially my gripe is that I'm not convinced of the usefulness of this > function and am concerned that it might be encouraging bad practices. In > particular: > > * As the RFC already mentions, iterable_to_array() can be replaced by a > simple and in my eyes very clear one-liner. This pattern would have to be > extraordinarily common to justify adding a function for it. Now imagine a large codebase with 50 occurences. Then multiply this by 1000 projects. That is a lot of "simple oneliners" with a lot of place for potential errors. In the end this is not different from is_countable() which was unanimously accepted. The pattern is not common yet because iterable is not common yet. One of the show-stoppers is incompatibility with array functions (or array hints in general). > * The operation iterable_to_array() *should* be rare. Please do not accept > iterable arguments if you are not just iterating over them. If your > operation requires conversion to array, then directly accept an array, > otherwise you are making false promises. If you want to use an array > function on an iterable -- don't. Reimplement the function to work with > iterables or use a library that does. Unfortunately, this is not true in real world, mostly due to BC and compatibility. > * The very close names of iterator_to_array() and iterable_to_array() are > somewhat confusing. For type declarations "iterable" and "Iterator" are > quite distinct due to different capitalization, but the functions are hard > to distinguish at a glance. I disagree, but I also believe this is a matter of taste/preference. > An additional issue is that iterable_to_array() preserves the behavior of > iterator_to_array() to preserve iterator keys by default, which is a big > footgun, especially in combination with generators. However, I also > understand that using a different default would be even worse, due to the > confusion with iterator_to_array(). Whether it's true or not, thatt's what iterator_to_array() does, and the behavior is neither deprecated nor adviced against in documentation. If you want to deprecate keyed iterator_to_array(), let's do it in 7.4, but I don't see how this makes this very RFC "bad", just by preserving behavior for consistency. Right now, it sounds like advocating the introduction of yet another inconsistency, something that PHP is very often being disliked for. Thanks, M.