Re: Optional parameters without initializer

From: Date: Tue, 04 Dec 2018 18:03:34 +0000
Subject: Re: Optional parameters without initializer
References: 1 2 3 4 5  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969387101@lists.php.net to get a copy of this message
On 3 December 2018 21:19:05 CET, Stanislav Malyshev <smalyshev@gmail.com> wrote: >Hi! > >> This defence sounds a lot like the perennial requests to distinguish >> an initialised variable from null. > >Except that it's not a request, it's actually what is already happening >right now in the language. I was referring to the bogus comparison to arrays. Let's send each feature on its own merits. >> discussion isset() on a plain variable. Varying a function's >behaviour >> on number of arguments fits very poorly into the language, and it > >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. >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. >> What I am saying is that on a case by case basis, we should examine >> these, and reluctantly keep only those that are too hard to change. > >And "too hard" should mean "causes any BC break". Fine. That's why I keep saying this is case by case, and some will fall into "we wish we could give this parameter a meaningful default, but can't". Regards, -- Rowan Collins [IMSoP]

« previous php.doc (#969387101) next »