Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122969 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 1F8FB1A009C for ; Fri, 5 Apr 2024 13:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712325287; bh=rZd5msyhMR5/N4xAbW4GpaO3O89FNQCDS3bKStB/l/Q=; h=In-Reply-To:References:Date:From:To:Subject:From; b=AsKMa7kwam9oAQd8K7TyXqk6oh3ePd6X2ycjma3OXuRfyXDt6cI+h026nnlh05JC1 eluyXnlYD3TcSrc4pF1/ZXlHA5Wc5WBj8WKqttmkQ1ZH8jW1AP4MAPf+KdatVZ/g/o Xx8aGUX7NfjE14p4Yh2dB31T41PMUTWNdI+wmuMKFRLgilgrtQ035VJZB67qS2Hbvd gdl6F5FtZnt4Cwy7VaSwkHClyZ4HJoDGfU/IEfUyi63cbYQy0qjw6CzaQiRFeEkzO7 ch+1UnMxEkqg90+fdI/Dl6+dEps2OfUZTt2M9UKPHYc0R86OYakA/x6Ft9IU7iYUA4 2IpqfXDXj1ZcA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F1B791804AD for ; Fri, 5 Apr 2024 13:54:46 +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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 5 Apr 2024 13:54:46 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id C194A5C0086 for ; Fri, 5 Apr 2024 09:54:16 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 05 Apr 2024 09:54:16 -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=fm2; t=1712325256; x=1712411656; bh=RqGa3sdPjyL3Q33xCTDtI z623mDl6hIZeB3e9vhkSho=; b=vac9oQ569yxMnrr0PHxsuyMfgqAO6ZGM9Ef6j eLHaHmOqpwItCQTGYaVURNayMMOeUEi4/j7jrWTWkNk71HJljQA8baF/YZu+zPc8 vXc8/gIK9Rc3ZdZK3HOfFnwBHQ3iybjBKOCWBCseZHuSHGI4XsJh412WBBdv9ecZ DLPJ3D/iiX7VHGJGvm7OSSdSWhWiPJ+8mn0RVUS49ME94Gur8BJ5FPur0LB5KFTT G7q9WaLchChCdaLpAjYPPZETlaP5A2QB0Wg0H7S8hiROeTVhPSKf1Bkh8D/zqdaB Z1Q8b2ZYsg4vk83BJ4vBNhSLPIvXgR5pnoOif7YqSxNUPlTAQ== 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=fm2; t=1712325256; x= 1712411656; bh=RqGa3sdPjyL3Q33xCTDtIz623mDl6hIZeB3e9vhkSho=; b=N Zs8T62XiCaZWj70uE8KeT0U/r8cyBIXm8edxiF+DQatOCF93v3VaxKfQ3zpHj2DA M/7vjtFlQI6bOTTk2fnQtwgExqvnEmiac7gth9zghxxqriSHdmjzakz4AW4cW8Wq XahezkiAxsLQkOKtin97IQGl6X26kVdQpgfPSmj1GqLwqpZfLtUa3KhZ7B7iryBA eXjL51bXXwbyroiRZ4FF/MrRP/UhOuTdFRZdB1yd8rAYiH/3lwYQoySxRZB2Ly0b 9ew2BTKsmDK6u530+sUufcfWSH113iU211uVczeqQgEV8JooIVHEoMi4dKkaXz17 pFxVitS51QawFgV2f4HBw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegtddgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne goufhushhpvggtthffohhmrghinhculdegledmnecujfgurhepofgfggfkjghffffhvffu tgfgsehtqhertderreejnecuhfhrohhmpedfnfgrrhhrhicuifgrrhhfihgvlhgufdcuoe hlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqnecuggftrfgrthhtvghrnhep heelhffhjeetuedujeehgedthfdtjeffheejteelgfdtffehhfehleffudeiheeunecuff homhgrihhnpehphhhprdhnvghtpdefvheglhdrohhrghdpghhithhhuhgsrdgtohhmnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhi esghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 62DDE1700093; Fri, 5 Apr 2024 09:54:16 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-333-gbfea15422e-fm-20240327.001-gbfea1542 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: <6299b649-c19b-4172-9632-2ef0a55d256d@uzy.me> <7B32AF65-CA40-40F5-BA59-CB5180EC4D7F@gmail.com> <8f71d807-78e6-49f6-acc7-b1fc09d815ba@uzy.me> <989e3e13-48ee-4970-8485-f79bb70ad37c@bastelstu.be> Date: Fri, 05 Apr 2024 13:53:56 +0000 To: "php internals" Subject: Re: [PHP-DEV] RFC idea: using the void type to control maximum arity of user-defined functions Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Thu, Apr 4, 2024, at 9:27 PM, Ilija Tovilo wrote: > On Thu, Apr 4, 2024 at 5:58=E2=80=AFPM Tim D=C3=BCsterhus wrote: >> >> On 4/4/24 16:36, Pablo Rauzy wrote: >> > I strongly agree in theory, but this could break existing code, and >> > moreover such a proposal was already rejected: >> > https://wiki.php.net/rfc/strict_argcount >> >> The RFC is 9 years old by now. My gut feeling is be that using an act= ual >> variadic parameter for functions that are variadic is what people do, >> because it makes the function signature much clearer. Actually variad= ic >> parameters are available since PHP 5.6, which at the time of the >> previous RFC was the newest version. Since then we had two major >> releases, one of which (7.x) is already out of support. >> >> I think it would be reasonable to consider deprecating passing extra >> arguments to a non-variadic function. > > IIRC one of the bigger downsides of this change are closure calls that > may provide arguments that the callee does not care about. > > https://3v4l.org/0QdoS > > ``` > function filter($array, callable $c) { > $result =3D []; > foreach ($array as $key =3D> $value) { > if ($c($value, $key)) { > $result[$key] =3D $value; > } > } > return $result; > } > > var_dump(filter(['foo', '', 'bar'], function ($value) { > return strlen($value); > })); > > // Internal functions already throw on superfluous args > var_dump(filter(['foo', '', 'bar'], 'strlen')); > ``` > > The user may currently choose to omit the $key parameter of the > closure, as it is never used. In the future, this would throw. We may > decide to create an exemption for such calls, but I'm not sure > replacing one inconsistency with another is a good choice. > > Ilija This is unfortunately not reliable today, because of the difference betw= een how internal functions and user-defined ones are handled. The code = above will fatal if you use a callable that is defined in stdlib rather = than in user-space. I have been bitten by this many times, and is why I= ended up with double the functions in my FP library: cf: https://github.com/Crell/fp/blob/master/src/array.php#L34 It's also been argued to me rather effectively that ignoring trailing va= lues and optional arguments creates a whole bunch of exciting landmines,= as you may pass an "extra" parameter to a function expecting it to be i= gnored, but it's actually part of the optional arguments so gets used. = The standard example here is intval($value, $base=3D10). Basically no o= ne uses the $base parameter, and most people forget it exists, but if yo= u allow an optional value to get passed to that, especially if in weak t= yping mode, you could get hilariously wrong results. (For sufficiently = buggy definitions of hilarious.) The behavior difference between internal and user-defined functions is t= he root issue. One way or another it should be addressed, because the c= urrent behavior is a landmine I have stepped on many times. --Larry Garfield