Re: Optional parameters without initializer
| From: | Nikita Popov | Date: | Tue, 27 Nov 2018 15:09:16 +0000 |
| Subject: | Re: Optional parameters without initializer | ||
| References: | 1 2 3 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969387094@lists.php.net to get a copy of this message | ||
On Tue, Nov 27, 2018 at 3:29 PM Christoph M. Becker <cmbecker69@gmx.de>
wrote:
> On 27.11.2018 at 14:37, Nikita Popov wrote:
>
> > On Tue, Nov 27, 2018 at 1:56 PM Christoph M. Becker <cmbecker69@gmx.de>
> > wrote:
> >
> >> Any ideas how to specify non applicable parameter defaults?
> >
> > We should use = null, and additionally make sure that this is really
> > accepted as a way to specify the default in the implementation (it's not
> > always the case, as it may require an explicit "!" in zpp).
>
> Well, I'd really appreciate fixing the implementation, but that might
> cause subtle BC breaks, for instance, if an explicitly passed NULL was
> internally converted to a falsey value with some reasonable resulting
> behavior, but now the NULL would cause different behavior. And there
> are some cases such as call_user_func() which do really have no default.
>
> Anyhow, the docs are currently supposed to document behavior as of PHP
> 5.0.0, so we'd need respective changelog entries.
>
> Either way, this may be quite some work, since I was able to find 1289
> files in en/reference with missing initializers for optional parameters.
> O_o
>
What I had in mind with the zpp comment are cases where we currently
error/warning if null is passed. But you are right that in some cases null
may be reinterpreted as 0. Usually it's fine to fix such cases (and we have
done this in the past), but of course it requires careful review. I still
think that this is the "right" way to fix the problem, if we are not in a
hurry.
For call_user_func() in particular, long term this should switch to using
the variadic function syntax that PHP nowadays supports, that is
call_user_func ( callable $callback, mixed ...$parameter ) : mixed
or possibly
call_user_func ( callable $callback [, mixed ...$parameter] ) : mixed
But I guess that would require adding support for variadics to PhD first :)
Nikita