Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122932 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 8992F1A009C for ; Thu, 4 Apr 2024 13:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712237243; bh=qA/o1UqGcQzr3hqM/tD340sIo756WvhTPOJPTO8GYt4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=XDgCELlm36/8JGRlajmjayFI8bwMW8dCikaqevzIzZmwvbjpOJmgRrpukuqdvaIrk gkAeRLqbE505xNJpmKDGGKrNJd8mZi8IhNyaN1KR5iNxlCoaBHENAMCASpXATlro2K WoPasIgNJhworMl0AKsKTXi2DEuoEhpe8VFR3hYxAV8iFY2+4aELwOtI2aNGnsjEll h8H03MA8Rz4TqyLWgW00pY/ws4BNfBDU41IAtQcObbKKu0Lgi8xtTzqoh7Cv2abUbx EWAJKUjY9oU0kArssuOe8CGPkBQo0GytoMaeTgpFVw0ZFxQpGkQB8qHa+3Dvz9EPc8 ge2YNx6GDFJJA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C12E31807AB for ; Thu, 4 Apr 2024 13:27:22 +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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,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-1908.mail.infomaniak.ch (smtp-1908.mail.infomaniak.ch [185.125.25.8]) (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 13:27:22 +0000 (UTC) Received: from smtp-3-0001.mail.infomaniak.ch (smtp-3-0001.mail.infomaniak.ch [10.4.36.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4V9Mpg5L6kzwD3; Thu, 4 Apr 2024 15:26:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uzy.me; s=20230717; t=1712237211; bh=qA/o1UqGcQzr3hqM/tD340sIo756WvhTPOJPTO8GYt4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=PWeXDbKn6Ka5GxuHmY0fQRJqK5jyAxZd3qREEWPab5u50qulpT/VfmtKB6xWI5iNY SkDbSzZwIpEsEsCdNJ8/5J74OZe/xIZmrUNElP3CvWprHIB08TQ8brx8291ugjxcbQ 2ClIuk9Hj4u3Koo5fWbS82LmKpj7xz4b8Bbo1GAaVr6or4OOsuAgo8n8rEqz6tK47k 3E1fq9AJay/qIP11jEyRr+nZU87uBYC8d7Yh1xFbNxfjawjOuUueEyhz+xGowuZGUS HMEafsyrfEcb613vW/dN86BagKIl63Theo3JgK4M9EXUhiPpNExxje732Fy5DiF1Az scCTNqQwkvoRg== Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4V9Mpg2Dhxzh9X; Thu, 4 Apr 2024 15:26:51 +0200 (CEST) Content-Type: multipart/alternative; boundary="------------mM2TByyy1BaVBiGC0YHKdpkz" Message-ID: <67221462-6c9f-48d7-8c59-e7262a744ff5@uzy.me> Date: Thu, 4 Apr 2024 15:26:50 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] RFC idea: using the void type to control maximum arity of user-defined functions To: Mark Trapp Cc: internals@lists.php.net References: <6299b649-c19b-4172-9632-2ef0a55d256d@uzy.me> Content-Language: fr, en-US In-Reply-To: X-Infomaniak-Routing: alpha From: r@uzy.me (Pablo Rauzy) This is a multi-part message in MIME format. --------------mM2TByyy1BaVBiGC0YHKdpkz Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 04/04/2024 à 15:03, Mark Trapp a écrit : > On Thu, Apr 4, 2024 at 5:43 AM Pablo Rauzy wrote: >> 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, > Hi Pablo, > > I like this concept, but instead of introducing a new syntax, have you > considered leveraging attributes in the same way that PHP 8.3 > introduced #[Override]? > > #[Nonvariadic] > function foo () {} > foo(42); // warning: foo() expects exactly 0 arguments, 1 given > > I think the intent would be clearer and it would avoid introducing a new syntax. Hello Mark, I never used attributes so I didn't even think of it, but that would work too, yes :). I would personally prefer the void syntax, but that's really because attributes look odd to me due to lack of habits (and also because it avoids an additional line of code… which is probably not a solid enough reason when it comes to language design decisions). Regards, -- Pablo --------------mM2TByyy1BaVBiGC0YHKdpkz Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Le 04/04/2024 à 15:03, Mark Trapp a écrit :
On Thu, Apr 4, 2024 at 5:43 AM Pablo Rauzy <r@uzy.me> wrote:
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,
Hi Pablo,

I like this concept, but instead of introducing a new syntax, have you
considered leveraging attributes in the same way that PHP 8.3
introduced #[Override]?

#[Nonvariadic]
function foo () {}
foo(42); // warning: foo() expects exactly 0 arguments, 1 given

I think the intent would be clearer and it would avoid introducing a new syntax.

Hello Mark,

I never used attributes so I didn't even think of it, but that would work too, yes :).

I would personally prefer the void syntax, but that's really because attributes look odd to me due to lack of habits (and also because it avoids an additional line of code… which is probably not a solid enough reason when it comes to language design decisions).

Regards,

-- 
Pablo
--------------mM2TByyy1BaVBiGC0YHKdpkz--