Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127432 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 lists.php.net (Postfix) with ESMTPS id AA3251A00BC for ; Fri, 23 May 2025 01:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747963384; bh=LO2SF821WzzVzPQtcnnnR7VoNWOH3gHmaVMY2M1R1C4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=WbzkFvEE97+EG8wLzA0h9uhRRV8sQfOXJWv/QzsGwFzsne0QyYDZbhi1npt2+gcKB qjuPJyPC1MDRYhz0aBy2+J0uarwr2C4jCqAi8MKUHCT1OPaNx/74TlNPxy25Q7qAuy BmHPoq/x2eJlNqW6elkSHLsITPjPNg1Ar2zSZQ60eFQdwRE9i54koxPHG3lvHx3NS2 JLrSTC6bSymK0A761LIN/eomWNvMtuW2agopT5vogVq/1dN7MGK9TYUETx2MNSZX+4 x1tFzVSigfcTmxJxl2nAHOsQpZ5J0y2512Nk31WJr4kxOZiuEr/eZaM1hLIbnoBfQY Za8uoZF3kDYLQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7657818006A for ; Fri, 23 May 2025 01:23:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-108-mta49.mxroute.com (mail-108-mta49.mxroute.com [136.175.108.49]) (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 ; Fri, 23 May 2025 01:22:53 +0000 (UTC) Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta49.mxroute.com (ZoneMTA) with ESMTPSA id 196fabe51b60008631.002 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Fri, 23 May 2025 01:24:58 +0000 X-Zone-Loop: 4300910d9310c09073522742ae6f56063454a061319a X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sandfox.me; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:Cc: To:Subject:MIME-Version:Date:Sender:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=+6ZGwNNRRd59iJVfIecPEFdv2VBYNSOvs1YmODTFC00=; b=Aig6vRu4SoMK RKHDMHmqNR3cPYtv9yZQGHRa1cm3jsABBunIYSZe4zZewSz+GpOI8M8R+jsfCK0BcgiUiKOyTeeE3 Z2VewObB4+ewpM3QtppPWN9SvgMoSydC6a/Mrz1mwagdhj1V02QTz2W56+XseUENgaU7WT0QgjfYe OiIhLyp4oKEA+hgemJJhgqWeW5rlkkirpGnHmNwEZdsOjt9JoslrSqxwHxowWmSLsPthBnwFlpaEJ Kx0wPCLWE/ZqK9b9xuHPNPT6d5+3spRl+mnoa4e/lBIjjdnrMqYBFxQXPJWgQQxDYJ+UBRJMeAHkl DlJzqdl5IR8AwTf4pqB+vw==; Message-ID: Date: Fri, 23 May 2025 04:24:55 +0300 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Forced named parameters To: Yogarine Cc: internals PHP References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated-Id: sandfox@sandfox.me From: sandfox@sandfox.me (Anton Smirnov) Hi Alwin On 19/05/2025 19:37, Yogarine wrote: > Moreover, what if I don't need a variadic parameter, but would like to declare that the function's interface requires named arguments (because I don't want to be tied to locking parameters to specific positions). If you don't need a variadic, you write an ellipsis without a variable name, like in my example: >> function f(Type $pos1, Type $pos2, ..., Type $named1, Type $named2) > So instead I'd propose to implement this using an attribute (e.g. `#[RequireNamedArgs]`) instead. That way, you could even make it so that only specific arguments are required to be named. It's also syntactically backwards compatible, so this feature wouldn't make your code break compatibility with older versions of PHP, and could be made available in older PHP versions using static analysis. Please explain the syntax you propose about this part: > That way, you could even make it so that only specific arguments are required to be named because I see only 2 ways to call it: #[AllArgsAreNamed] function f (/* ... */) and function f($arg1, #[AllArgsAfterThisOneAreNamed] $arg2, $arg3) because function f($arg1, #[NamedArg] $arg2, /* positional again */ $arg3) doesn't make sense, you cannot specify a positional argument after a forced-named because it would be impossible to fill position 2 on the function call. Both cases are better covered by my syntax. > It's also syntactically backwards compatible Making it syntactically incompatible is what avoids the BC break and relying on userland static analysis seems to be discouraged in this community. Consider this scenario: let's say version x is the first one with the feature #[RequireNamedArgs] function f($a, $b, $c) { /* ... */ } f(1, 2, 3); // works in x-1, broken in x so this feature should at least go through the deprecation-like phase, and be fully accepted only in a major version, which just means that it cannot be fully used until the next major version. That defeats the purpose for me. Anyway, the biggest problem for me, why I'm not considering writing an RFC for now, is that I don't know what to do with func_get_args() and reflection.