Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123246 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 D33C81A009C for ; Wed, 1 May 2024 10:26:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1714559256; bh=nsk7gHD378fRHG/s+enKs66bRVX3tSxF5AQelL8/TGk=; h=In-Reply-To:References:Date:From:To:Subject:From; b=aHNisifn6glXhGrLnSSsP/KTawOtmbZDwFqg5hUiOFXFCKmLAPx0krDjm36EYwB+B Yu0C5Bn252AuuGsJSc8qPIemCVbzxSVT+aF5kRqWIM6NzNyOWh7jmiidpy1PUmEyAM LQP/mm3RQx+H6KjZeAxma7C+/RjGYtk5J0fTK3UIVncBPg9v/vKATyEGixifEJV4dQ Vhp8LSXo6+2rOGNf5BUR/UgNYhcD0gkWtGpzd2gptds2yx29CuDwuRsW2Nm54pQvh4 RxlksIXwudxWws+37YnTp4cqEcqAYU8j9R/LZQwNQanIZa5VNW1BxdabL1IJek1OLZ kDuamZpndVsyw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 07C13180061 for ; Wed, 1 May 2024 10:27:35 +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,T_SCC_BODY_TEXT_LINE 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, 1 May 2024 10:27:34 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 74C75138017F for ; Wed, 1 May 2024 06:26:49 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Wed, 01 May 2024 06:26:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=fm3; t=1714559209; x=1714645609; bh=In0G4/FVtEWZl/GYSX0/J 2DGAQX/oM1RhtWJTrg/5Lg=; b=vIs3wBXQbeM5N2O6Y09m/24Y8XWlZyH4846cb ICgL4I8frmia4M6Xt873zciQy5aNwDESvLFbNN7NUJa2RtJpqY95SAr9iari2qIV 1MjMMUH3KzoAs9F7n6WaoHsdfB9AXiZ0Bzeoohfo4ojZTec7NC5fToGP0b45TLb6 ykIuzzbPIt93odr99/wacLyVu09l5vbXmI0+7fr3KMDGGT6r+FPsW67hiPLE08gE bGfWzIzUvTHt2EopL1gB8JZLAUALqNBaqr+XU7pDFfIhLlcP7vABX40w6KLwqFR0 I/zyNrXENq7gGec6QazbmXuQCmQ8ndiqR2fH9IuZh9A9tJ3mw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=fm3; t=1714559209; x= 1714645609; bh=In0G4/FVtEWZl/GYSX0/J2DGAQX/oM1RhtWJTrg/5Lg=; b=d 8Ms5ZmzuBviDKthNPg3/BPIzjYwWPq0YXH2vXwQjWJPg6cVKNlTsI2ywn2KT84lW OYv5AApoh85CUaAk7LtxtLa8b+jc4bNpE8xKDBtqztBsbbsGSpaIuSq9t+CoNi9D 5vhZ8IzwUX6qAUe9Mb13LowVWi3OhqHVAeXh2kQUXQT2KzOnQczJvMS/9WGAspzw vpXK8QGVEgg0UuDTchyKz15EHT/yrydXckNv8Fk8vMObQd1yAxBN0a3TPn/QUZFq u90ayU93jzGMtatpouXyjrQ2IA6HElnmynNRbtbwy8g8hk4CVSMG/bytY3NfRBUz nfKiGXuGOmKe1I96DVg3w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdduhedgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeeghefgteejheeggfeghfelueeggfdtjeeivedv tefhveeguedufeelhedvteeinecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf ihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 09DA71700093; Wed, 1 May 2024 06:26:49 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-416-g2c1796742e-fm-20240424.001-g2c179674 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <60bb55a5-16c9-4df0-8521-75f82d3dbf5b@app.fastmail.com> In-Reply-To: <45e6365b-4963-4969-8cc1-80bae6922fc8@wcflabs.de> References: <24e4529d-0b75-44de-90ef-34de5dfb1c99@wcflabs.de> <278889be-82ab-4827-a9e7-801b5ba2d8f8@app.fastmail.com> <06373f2b-5de0-4582-96c5-29c3b474c01d@wcflabs.de> <45e6365b-4963-4969-8cc1-80bae6922fc8@wcflabs.de> Date: Wed, 01 May 2024 10:26:19 +0000 To: "php internals" Subject: Re: [PHP-DEV] RFC [Discussion]: array_find Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Tue, Apr 23, 2024, at 7:53 PM, Joshua R=C3=BCsweg wrote: > Hi > > On 19.04.24 21:20, Joshua R=C3=BCsweg wrote: >> I definitely see the point where there is an advantage to having two=20 >> separate methods and can definitely understand that it is easier for=20 >> developers to understand the control flow without evaluating the=20 >> parameters. >>=20 >> I'm unsure if that's really necessary though, because basically it's=20 >> probably not necessary to directly see what exactly the function=20 >> returns. Perhaps there will be another opinion on this in an email in=20 >> the next few days. > > Now that I've thought about it for a few days, it's really better that=20 > the whole thing is broken down into two methods. I have adjusted the R= FC=20 > accordingly. The RFC contains now two separat functions `array_find` a= nd=20 > `array_find_key`. > > Cheers > > Josh This looks good to me, with one remaining exception, which isn't specifi= c to this function but should still be discussed: Always passing the val= ue and key to the callback is unsafe, for two reasons. 1. If the callback is an internal function rather than a user-land one, = and it has only one argument, it will error confusingly. That makes the= current implementation incompatible with unary built-in functions. See= , for instance, https://www.php.net/is_string (and friends) 2. If the callback takes two arguments but the second is optional, it's = highly unlikely that the key is the value expected as the second argumen= t. This could lead to confusingly hilarious errors. See, for instance,= https://www.php.net/intval. These won't come up in the typical case of passing an inline closure (ei= ther short or long form), but are still hidden landmines for anyone usin= g functions not tailor made for these functions. I'm not sure of a good solution here, honestly, so I don't know what to = recommend. In Crell/fp, I ended up just making two different versions o= f the function that pass one or two arguments. I don't think that's a g= ood answer for this RFC, but I'm not sure what is. At the very least, i= t should be mentioned as a known-limitation that gets documented., unles= s we can come up with something better. --Larry Garfield