Re: RFC idea: using the void type to control maximum arity of user-defined functions

From: Date: Thu, 04 Apr 2024 14:29:18 +0000
Subject: Re: RFC idea: using the void type to control maximum arity of user-defined functions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-122933@lists.php.net to get a copy of this message
> Le 4 avr. 2024 à 15:03, Mark Trapp <mark@itafroma.com> a écrit : > > On Thu, Apr 4, 2024 at 5:43 AM Pablo Rauzy <r@uzy.me> wrote: > > 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. > Indeed, except that I think it should be better to have *by default* the same behaviour between built-in functions and user-defined functions: ```php function foo() { } foo(42); // in PHP 8.x: Deprecated: foo() expects expects exactly 0 arguments, 1 given // in PHP 9: Fatal error: foo() expects expects exactly 0 arguments, 1 given ``` and, in case you want a variadic function: ```php #[Variadic] function foo() { } ``` Alternatively, we don’t really need to introduce a new attribute, because one can just write: ```php function foo(...$args) { } ``` —Claude

« previous php.internals (#122933) next »