Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124458 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 21BD81A00B7 for ; Wed, 17 Jul 2024 14:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721225030; bh=KrQJZIOns9luc19xYtTsWS8X4PmolAsEYIU2vBbV4Mk=; h=In-Reply-To:References:Date:From:To:Subject:From; b=PIzCgzHUBsXEKklQd+e9+sg4vCk8V0V+BhWRJLGSImgxQV/AVmwVGmdUnGrhkCCfO Oxd6ED+JSXxfoHeWtmNbpmOSk8ZAngjOEBU58mMl4wgn2DBv3Q5dctH/5ru0YM09ha dAQkqsVA5QUfOEsb8WIO91lD4bABnZh5IWgbmixPZTOHwP4y3vKp3+pWI5gpx/N3+d iEM/0fQT0UL24JAPaRVDUl6Y5eeBdfoXjKqBPd7XOAUUJS9b3aBfMiXIyFTSuqwSSU HyGhUqUu+wzPCIWPcdYBiUT8JonmzkuEQXp7eF+iwEHrq+eWNxks/T/fnBglEWE/ff uofskahaju9TQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 25B4A180069 for ; Wed, 17 Jul 2024 14:03:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 17 Jul 2024 14:03:48 +0000 (UTC) Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id 11A0F13800DC for ; Wed, 17 Jul 2024 10:02:18 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute8.internal (MEProxy); Wed, 17 Jul 2024 10:02:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1721224938; x= 1721311338; bh=nwOi9fR3pqj70s3fL7XV++cASdCfhXIHk1iBNC5lT74=; b=H ep131bRE/wcX19zTS/yG33RB50SA1Bq+Gd4FZSyVyB89owX0rCsDL51CNSiNPrXs gu92XUJMvQVsmWRrsBZd+7HUfHgaTkhLndDeweFNIJluwXoVjNgsVDfhf53FxotE R/dnejujH2xyPL+qlRLqZIyQd2JwMjAesR7XapGIg7gUNLnuD8qDNXiFzMaieGSX 8Nu1rDWzLLpH3FpVOqK+Osz9ossvd03q8lTzgbM8xN2Y69RoW4Q9qI4Yxpck1+T1 +G5efI/2tueIbkdKxemu35Uiy6diIKY4Lnf1AS/PbT/NjMPbCYQsiVTNbrZpzQw6 fYr9JhE3od8g0hbI/R42A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1721224938; x=1721311338; bh=nwOi9fR3pqj70s3fL7XV++cASdCf hXIHk1iBNC5lT74=; b=gQM6qV9266Y8oSLszPR0dNvx4KLosxsfw9LJVIEZkKX4 JUYoqVC8wjCf+dZCee/YWdxkvOgEeLic1Tf/aHIpsMlfBq5j0joKekyZP1OrswC3 dvdkhYHaUdMbRQAmjSsObRieXGI4eMrJ7IFB0dnf1gqC1CQ8HRqkVErHkmx29lHM 0knqrUJODpWPwuA8HzjQJxifSh3rMMiJC7eut1DJYP2vjukjB+T8XfWLOuREImhD TFCvMUfF5L/YhtGTreTNSup9QuKPlA7f2u8FAf0B0l2ma1YT4tl2nCP2Lw6CO152 Jq2XnkKl81bvTl1HruMB1eGaU/tbluRGLxmH7OOkBQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrgeeigdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepfeetveffteetueeukeegjeffudeuhedthfevfeehiefh heegheffhedthefgleejnecuffhomhgrihhnpehphhhprdhnvghtpdhgihhthhhusgdrtg homhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehl rghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 8B00E1700093; Wed, 17 Jul 2024 10:02:16 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-568-g843fbadbe-fm-20240701.003-g843fbadb Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Message-ID: <798adb8d-ae06-49a7-bf2b-fd0037a374c0@app.fastmail.com> In-Reply-To: <356aa359-e109-4b2f-82e2-e15fcaf0c64d@scriptfusion.com> References: <5bdbffef-4954-415d-9dae-4c9bd4ba0f22@scriptfusion.com> <356aa359-e109-4b2f-82e2-e15fcaf0c64d@scriptfusion.com> Date: Wed, 17 Jul 2024 14:01:55 +0000 To: "php internals" Subject: Re: [PHP-DEV] array_reduce callback key Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") On Wed, Jul 17, 2024, at 9:01 AM, Bilge wrote: > On 17/07/2024 01:41, Levi Morrison wrote: >> Adding arguments to a function can mess up internal callbacks, btw, so I don't like modifying the >> existing function. > Which internal callbacks can be messed up by this change? They clearly > aren't tested, as the build is passing. > > Cheers, > Bilge There's a number of issues here. PHP-defined functions ignore excess arguments. C-defined functions error on excess arguments. A function with an optional second argument... may break if it gets passed an optional argument that isn't aligned with its expectation. intval() is the usual example (https://www.php.net/intval), but it would also impact something like trim(). If someone is using a function with one param and one optional param as a callback right now, suddenly passing the key as the second argument could cause all sorts of weirdness. Similarly, if someone is using a single-param C-defined function as a callback right now, and array_reduce() starts passing a second argument, it will fatal. I ran into this issue while building Crell/fp, and my only solution (after swearing a lot) was to just make two separate versions of every operation: One that passes the key and one that doesn't. (cf: https://github.com/Crell/fp/blob/master/src/array.php) The user has to pick the right one. That is, sadly, the only reliable solution, even if done in the stdlib. (Of course, the real solution is to introduce a separate map/dict type that has its own dedicated API for map/filter/reduce, but now we're well out of scope... Using the same structure for lists and maps is PHP's original sin.) --Larry Garfield