Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111727 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85575 invoked from network); 30 Aug 2020 17:27:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Aug 2020 17:27:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 85C041804D9 for ; Sun, 30 Aug 2020 09:31:21 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-oln040092004012.outbound.protection.outlook.com [40.92.4.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 30 Aug 2020 09:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kGfV9KaCFyU8kuQcYgF1tZYXQ4duihCUgvOdz2GqeAex6beWFuBJGWir39DkvZHldfR6QuLnw2iog2fj8viIS4T3eG0QNF8eikfllDzV0VA5QWpOn6Fc5Z4UBXWztpUZqaUa9ohHFYa6qulT4kPcYNNpWdi356jGgaYAW42OCX8RC3/3Toc6izfDwacdZF2FGBvz0JbntTfIWswoq6C9dzwOJwwxICgfY+KqluO1+yJt9l3hyl8jZEHKFxaF8YqWhfp2q+pcA/Za5gw4o1F6IBgynxmIrq+rfkFeg45P0WXdAoKq8L9vAaNjBtqSxrmGwRS+8ZT9K7cDYNx1rzn/0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cVhPH8kZo4K5sm5mI6wzaY7vA00Zlw2DBUcxzdKwusI=; b=InXLt9nCiw+T50pqFd00tedm8bNY/xSMCe3GetcgNnuT+RV14zZl1Zb5dF5l3p4yS1XfsZjA+sl+85QtPQUYTxWEnbdfEo0bT31M8gE+Sos300GTI6LoiaYTaEQk2BuYqwZs6Nr/nEPDs3oJ6y6fjMQjj2sichklR/Cm8zJrv0UeZn8LjXLgIWh7mfg83nfAsO2hyLbkDTAUNW5kUN5vNDbcPOaQ9sfsOdOZkojX9EnUOHBxmBbjjjhtlMwUe2Ou9rYWb3fQ56+NpW/wRtvZ3b/D+btH7RCz6gsbUQ0FrGraTT3DcNuzyi8ZKcOy0ndGV67chfHR4XYKi98dRveJiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cVhPH8kZo4K5sm5mI6wzaY7vA00Zlw2DBUcxzdKwusI=; b=L/RNe8RGH3MU3FVSVb2R1hHkRto+059wIlgpSwQd0ETSoCiy+xmc/ig5Juf+kuDjaj+HOSbPyDDm+3ybUCLhphZ9VyUWxDuE6mZKdJ/c5NZ5rRTaNP3NkK9CCel32xhGRkUPw01w1KqFaHtDMp8Lt6jKNWd+h1hAwrLZsoJAj0zdo0FcbqGV3NV8XUKTbtXT9NaVtm/DBExubIUJbMuAwJhKOoeui5nqtO6D+Rtc+jRUSXFcKNdeDvc+KZAE7IbUiHKMXG4+zDZ3PmvTsGEvT7vaWlxPJpuXuBQA6UR61ZDKTEyxPl7FBzqSGUMM8ihMPLmGv13SnyQc8HJiCZi0fw== Received: from BL2NAM02FT031.eop-nam02.prod.protection.outlook.com (10.152.76.55) by BL2NAM02HT125.eop-nam02.prod.protection.outlook.com (10.152.77.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.21; Sun, 30 Aug 2020 16:31:19 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e46::40) by BL2NAM02FT031.mail.protection.outlook.com (2a01:111:e400:7e46::429) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Sun, 30 Aug 2020 16:31:19 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::f9d1:ed5b:8625:bfb4]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::f9d1:ed5b:8625:bfb4%7]) with mapi id 15.20.3326.025; Sun, 30 Aug 2020 16:31:19 +0000 To: Mike Schinkel CC: PHP internals Thread-Topic: [PHP-DEV] Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) Thread-Index: AQHWfj2/bRooGr39CkeRSgZBGY4s+alPjGGAgAArEDGAAHp9gIAAp0UT Date: Sun, 30 Aug 2020 16:31:19 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:611C27C55DBFA8AB83D4DC8553ADEC9B7E2500D49638D61E569743013E0601BC;UpperCasedChecksum:68E363FEC1DC58AC64360E5520627AE37B3B96A998B4FF182AE109BC15732E66;SizeAsReceived:7429;Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [A4/n1Sa6AcNBtDdS9BOWwiPYHoO8yRQ413aN3MDUSvR/Pv1YDOMf/ezO/qnDoBt8] x-ms-publictraffictype: Email x-incomingheadercount: 45 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: fe8dee12-ea58-4dd5-4054-08d84d02200c x-ms-traffictypediagnostic: BL2NAM02HT125: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: io4KyjWxaVxrxaAxRivTQSbSS+l/lhgy28e4uLZXo4zzL/BO7s+Bj/Hv9DIhTuyUAhgSqcE+y07mTjE29iu0iK2en0jv1T5RQ2ZzT9T2vXzt1aK/pqOOhW0RSTjNYsd9nx7FrfRdHnhdZryVKA5vMXxhztBrxJ/m3dfeiLFcpO8no1ToZAhQDWxaj4rPkdRX31cqMrannpYm3dq6ipDp+Q== x-ms-exchange-antispam-messagedata: UguO15Kwm7dcdU/PkTGM/6IXATCtiV9L6VvjUrE8ue+VhNXrikPTxHNDIyuzoSXo/nN5o5ttnTOi/qWF2ONSsLHZUTrEQ8pBSw5E5jspy2p5F7dYbd5COZ3DnAclbQSqs105XHxBNvTS2WeYDOyZb/XNmmZmW8aNsKFEHfnINXlAb3uDZELBQ1vLQZF6b1Zw9HSnvDIDNf3eL1/HduXrvA== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: BL2NAM02FT031.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: fe8dee12-ea58-4dd5-4054-08d84d02200c X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Aug 2020 16:31:19.4952 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2NAM02HT125 Subject: Re: [PHP-DEV] Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) From: tysonandre775@hotmail.com (tyson andre) Hi Mike Schinkel,=0A= =0A= > Doesn't the occasional required use of long constant names like ARRAY_FIL= TER_USE_KEY and ARRAY_FILTER_USE_BOTH somewhat negative the benefit of a mo= re concise syntax? =0A= > =0A= > I know that many existing functions in PHP have a collection of long cons= tant names that can be passed, but is that a style of programming that PHP = really wants to continue to proliferate, or would it not be better to addre= ss that use-case in a different manner? (Admittedly doing so might requir= e having this feature dependent on other critical path language features.)= =0A= > =0A= > One approach might be if PHP could allow for skipped parameters in callab= les =97 where I am using a single underscore to indicate an unused paramete= r (GoLang has a "blank identifier" for similar purposes so there is some pr= ior art to consider) =97 e.g:=0A= > =0A= > - the default is `any($iterable, fn ( $value ) =3D> ...)`=0A= > - or `any($iterable, fn ( _, $key ) =3D> expr )`=0A= > - or `any($iterable, fn ( $value, $key ) =3D> expr )`=0A= >=0A= > PHP could handle it more generically, is possible, or recognize this and = branch to different implementations of any() and all() if the goal is to op= timize performance by only passing one value in key-only or value-only call= s.=0A= > =0A= > Optionally we could use null instead:=0A= > =0A= > - the default is `any($iterable, fn ($value) =3D> ...)`=0A= > - or `any($iterable, fn (null, $key) =3D> expr )`=0A= > - or `any($iterable, fn ($value, $key) =3D> expr )`=0A= =0A= Supporting "blank identifiers" is out of the scope of this RFC,=0A= and would have some implementation concerns of how it'd work with named par= ameters=0A= and how backtrace generation would be affected. I don't think there'd be a = significant performance improvement over not using parameters.=0A= =0A= I'm taking $flag out of the rfc because there's many proposed alternatives = for doing this,=0A= and checking values of an iterable is the most common use case.=0A= =0A= Repeating the response to Marco Pivetta,=0A= I find that checking parameter counts would be inconsistent with how other = internal functions accepting callbacks such as `array_filter` already behav= e.=0A= It would also be unexpected if users or tooling wrap callbacks with other c= allbacks.=0A= Developers would also expect `func_get_args()` to work.=0A= =0A= ```=0A= $predicate(...$args));=0A= }=0A= // PHP can't distinguish between these when given `fn(...$args)`=0A= // - would throw if passed 1 parameter=0A= my_none($values, fn($value, $key) =3D> $value =3D=3D true || $key =3D=3D 'x= ');=0A= // - would throw if passed 2 parameters (too many)=0A= my_none($values, 'is_string');=0A= ```=0A= =0A= Cheers,=0A= - Tyson=0A=