Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122948 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 6EB0C1A009C for ; Thu, 4 Apr 2024 21:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712266111; bh=8yp/QwLptV7T7sWfTyMlSNcD3dayJWjquoawIprwTEI=; h=References:In-Reply-To:From:Date:Subject:To:From; b=l9nQXUENuo3iQPPdu02CZ7BkpIvVyJnT+Hj0D8YXZSR83rfqlDo6L9U+6PyoqFdC4 aJHuUqtcbmzBcdJ4xDaGtbyT6kSWDY7t5x2UnGgFdo+FctQ2voaw1LYeC5COfmWKoc 46S0fcg/LwdCSF9SeqYEqDuKc9hnf5Eo29Rk/J9fb6SBBF/mMk4niEWMHn0PfFK4KI Fcr0FNJfQCBGpmnHHduPyXGkB+CrQNo5OXwdf0z4Bx8onYKoiO84sXs9cUn+mCS+xJ ost/QVj6pFwiQrt3H3wLTz77gVnNGfJNWKKDWFOnATzg0Aq4GSn30sgjq7F3PlcDZj yVntLiIkQNEWw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 81C52180041 for ; Thu, 4 Apr 2024 21:28:29 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (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 ; Thu, 4 Apr 2024 21:28:26 +0000 (UTC) Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6990b53a2cbso21154886d6.0 for ; Thu, 04 Apr 2024 14:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712266076; x=1712870876; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2CmyoRo2BK3Lvz5g1TtUt75Atx5E6LBccjOtnKHhnZk=; b=MX9S/cUPPs3Z/ogLbexG1igbs0czzu0qafCUJkcoxGZ9k2gwPrNLkJ8RfO8v0MwayQ uXmHjx8epeuPM3j8wSSVbmd9QbH3p9/laDKCujlZezNm9okry7TlCWqoabxEC1vvxjtB 6yI/0j8nJ4sdTymbyuyPQ1Q6HUNe0j3tf7bafH2OBZ+7sMA+fLBB//hFglxVlclEE65h X+O2uywPW6DMwK4HE6SB7GXxDblfIOFyJoEKD1xXe+aTq3fprstSdtVt4bMapWaIPUDO IQKazx6iOkZcn5c0G45CmS6rzxJz3iOD7qVycEOvtXOZKjp/CLVb0T7koqyFhhZKm5ZU AAqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712266076; x=1712870876; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2CmyoRo2BK3Lvz5g1TtUt75Atx5E6LBccjOtnKHhnZk=; b=eIMTV2tePFLO7ouB6di6qVJinvJBSy50/pm4U31o9AS1TtScIce4uBzP8uAavB1QnZ 0N96Va5grAh74ofTiAEUcvoSF7O3+87IWp3gcvl6/eIv6UPoNlHE/9dxq6I23wPsV+0h HKgobOs+dOE0KsNWvsTg/PNVnNaizF3vP4sjo4AL1phXbwMB3ZZfDyC1i/sgrvPpvldb bivRdPMfdDD7U8eo4hl4NpjoaZNbvlyWAbDqLwFkCnWKarVMkmf/w6sCOdcYjY/NA27L SgCNmjt7JEogi77OY2RzY0O7LowALc30tu7zYH3/cBnd+xhc0WeTX18x6jOriII/bhnw tKTw== X-Gm-Message-State: AOJu0YxHdNqoCvZfn0aLygUIxCPazKMovE7Lu3NuWjO3cu/IpoM85gzP JgUqtFENB5NXvIrHhbgLhkIAHiihBS+oZyJT+7aFe6woSgM2mu7YCTiDBQce+JYDqBDKcTKsR1i IEPxUvUNdkW1Zv0AoyyVt97ig8m1sD1Gs9gnwWQ9L X-Google-Smtp-Source: AGHT+IGEHnbhp5HvveYnQJNpm00TfV4Ve5ey48LPjeZOz3wxdZBIaaQe7XOZGsnB5fQylUOHdsImtUJ9lYZhE+1FLoE= X-Received: by 2002:a05:6214:1c0d:b0:696:755f:c0cb with SMTP id u13-20020a0562141c0d00b00696755fc0cbmr1436918qvc.8.1712266076441; Thu, 04 Apr 2024 14:27:56 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 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> In-Reply-To: <989e3e13-48ee-4970-8485-f79bb70ad37c@bastelstu.be> Date: Thu, 4 Apr 2024 23:27:45 +0200 Message-ID: Subject: Re: [PHP-DEV] RFC idea: using the void type to control maximum arity of user-defined functions To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) 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 actual > variadic parameter for functions that are variadic is what people do, > because it makes the function signature much clearer. Actually variadic > 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