Re: Optional parameters without initializer
| From: | Rowan Collins | Date: | Mon, 03 Dec 2018 20:03:44 +0000 |
| Subject: | Re: Optional parameters without initializer | ||
| References: | 1 2 3 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969387099@lists.php.net to get a copy of this message | ||
On 1 December 2018 02:48:46 CET, Stanislav Malyshev <smalyshev@gmail.com> wrote:
>Some functions behave differently when you do not pass any argument
>than
>when you pass an argument, even null. Changing it may lead to subtle BC
>breaks in existing code - e.g. anonymous connection to a service and
>connection with username/password set to empty string may be completely
>different actions.
>
>Even in PHP userland, not having a value (e.g. array key) is different
>from any array key, and is not representable by any setting of the
>array
>key.
This defence sounds a lot like the perennial requests to distinguish an initialised variable from
null. Parameter lists are not arrays, so that comparison is just as irrelevant here as it is when
discussion isset() on a plain variable. Varying a function's behaviour on number of arguments
fits very poorly into the language, and it would be a lot less surprising to simply give those
parameters a suitable default.
I totally accept that there may be unacceptable BC breaks here, so I'm not suggesting we
blindly replace every case with a null default. 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.
Regards,
--
Rowan Collins
[IMSoP]