Re: Optional parameters without initializer
| From: | Christoph M. Becker | Date: | Fri, 07 Dec 2018 15:58:34 +0000 |
| Subject: | Re: Optional parameters without initializer | ||
| References: | 1 2 3 4 5 6 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969387102@lists.php.net to get a copy of this message | ||
On 04.12.2018 at 19:03, Rowan Collins wrote:
> On 3 December 2018 21:19:05 CET, Stanislav Malyshev <smalyshev@gmail.com> wrote:
>
>> I am not sure what "fits very poor" means - it's part of the language,
>
> It fits poorly in the sense that the language, in userland, does not have function overloading,
> either on number or type of parameters. You can emulate it a bit with func_num_args() etc, but it
> wouldn't feel like idiomatic PHP. I'm generally not a fan of built-in functions behaving
> in ways that userland ones wouldn't.
ACK. However, that ship has sailed.
>> and has been for decades. Just declaring after 20 years "no, I don't
>> like it, let's change everything now" is not going to work.
>
> I will say this once more: I am not suggesting we suddenly change everything. But if
> there's a function where currently passing null doesn't do anything useful, but missing
> the parameter does, why not consider declaring null the default, to add functionality and increase
> consistency.
I don't think it is useful to provide default parameters for
“overloaded” functions; instead I would rather document these functions
with two or more signatures, even though that doesn't fit the arginfo
(i.e. Reflection). Consider a typical example where we have foo()
instead of getFoo() and setFoo(). Calling foo(NULL) not only often
behaves as such (converting NULL to a falsy value of the expected type),
but it also looks like a setter.
--
Christoph M. Becker