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

From: Date: Thu, 04 Apr 2024 15:40:59 +0000
Subject: Re: RFC idea: using the void type to control maximum arity of user-defined functions
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-122936@lists.php.net to get a copy of this message
> 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. > I agree that using an attribute would be better for this case. > 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). As a reader of the code, having the attribute is much more clear to me than having something that looks like an argument. Also, with attributes, the code is backwards-compatible, i.e., I can add the attribute to my code without any errors or warnings even if I don't use the latest version of PHP, and even in those cases, IDEs could still help me.

« previous php.internals (#122936) next »