Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122928 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 3245C1A009C for ; Thu, 4 Apr 2024 12:41:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712234545; bh=ABJ8E5jc2B/4J0NRuMUiqQMg0gzQMgZBYbeAQPf1gH0=; h=Date:From:Subject:To:From; b=NkDyNbu8vSKFLLBTYXWxBaOjH5v8LYB2tjer8aF4qWclMva6eJcZNkUMwX5xC4PT1 vorL5VKzT6WcahK5IfGCa0yTwo53hRjgbhQQTgrLWjRH8rAzTSJWLwzFvoYBCVsOxd y9ENLBK9Dok75NbgSNpjYtTyyuvOqSly1QJobPRqu/XxwOthnzbRiZN4DnxuatOmpN kFeslBaQeqOiaVnpC915VPLJ3HmEpfyUZg8VefCC5tlpzCwI4UbrLTyfBWUE3gL3TA NBVzikMVbg/+WgJq6J6BWjW1socO0SLyXzTwECxJIx5bqNGTqKBAxNC9ezDjsyOZMj enXdpLUPrTg4Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F2F6E180656 for ; Thu, 4 Apr 2024 12:42:23 +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_MISSING,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 smtp-bc0b.mail.infomaniak.ch (smtp-bc0b.mail.infomaniak.ch [45.157.188.11]) (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 12:42:23 +0000 (UTC) Received: from smtp-3-0001.mail.infomaniak.ch (smtp-3-0001.mail.infomaniak.ch [10.4.36.108]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4V9Lpn15jnzYJ5 for ; Thu, 4 Apr 2024 14:41:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uzy.me; s=20230717; t=1712234513; bh=ABJ8E5jc2B/4J0NRuMUiqQMg0gzQMgZBYbeAQPf1gH0=; h=Date:From:Subject:To:From; b=knWrCL2mslCkK3QKIVlTkIpQSRP+dRTuonLo2HxmyfA8FMtyU3h7WbTxfhSBR6fEl uWSNa7YryJmJLUhb7KeE2q+wazGPn/xWRDcisIy3Wmo4spYMHRFpjyqX/2/pwUTn9l iWk38wHAC4ZJ33ed8dNmdut5K3Xq0r45B/JrqXuPa5wudTNsDb1L0sLAfYNmN+583x Ilj6UeLux1vkRrM2rk8RhbKkcax7o0VV9nVXk0C9UBINFCHoCO/0m8Slbhnw1tvqpw 0B7hKl5bdxzJlGcU11L5Z8F1+Hgj/QAhJqQIDw3a1GpY9OyB7Pr1bnUbWbv7Dj6YdA o2TXdk/WHo7uQ== Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4V9Lpm5p4CzNxh for ; Thu, 4 Apr 2024 14:41:52 +0200 (CEST) Message-ID: <6299b649-c19b-4172-9632-2ef0a55d256d@uzy.me> Date: Thu, 4 Apr 2024 14:41:52 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US Subject: [PHP-DEV] RFC idea: using the void type to control maximum arity of user-defined functions To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha From: r@uzy.me (Pablo Rauzy) Hello all, First, I'm new here, so let me start by warmly thanking everyone involved in PHP development. I've started programming 22 years using it as my first programming language, and still enjoy using it a lot :). I've read the rfc:howto and the first step is to get feedback from this mailing list about the intended proposal, so here is a short description of what I have in mind: Currently PHP does not warn when user-defined functions are called with too many arguments. Changing this could break a lot of existing code, but it would also be a very good verification to catch potential bugs. I have an idea allowing this feature without breaking any existing code: using the void keyword in a function arguments list to strictly limit the number of arguments a user-defined function can receive, stopping it on the void, which could only be used once and in the last position. Currently, void is a return-only type so it isn't used in arguments list in existing code, so I believe the new behavior would only concern newly written code that explicitly wants to take advantage of this feature. A few examples using functions (the same would apply to class methods, callbacks, closures, etc.) :     function foo (void) {}     foo(42); // warning: foo() expects exactly 0 arguments, 1 given     function bar ($a, $b, void) {}     bar(1, 2, 3); // warning: bar() expects exactly 2 arguments, 3 given     function baz ($a, $b=null, void) {}     baz(1, 2, 3); // warning: baz() expects at most 2 arguments, 3 given I have no knowledge of the PHP internals: would that be feasible without breaking things? And, as importantly, would it be a welcome change? Cheers, -- Pablo