Re: [PHP-DEV] Re: Warn when declaring required parameter afteroptional one

  108404
February 5, 2020 09:49 nikita.ppv@gmail.com (Nikita Popov)
On Sun, Jan 19, 2020 at 10:15 PM Andrea Faulds <ajf@ajf.me> wrote:

> Hi Nikita, > > Nikita Popov wrote: > > > > Since nullable types have been available since PHP 7.1, having a required > > parameter after an optional one is increasingly likely a bug rather than > an > > intentional workaround, so I think it would be good to throw a warning > for > > this case. > > > Wouldn't it be trivial to special-case `= NULL` here to not cause a > warning, or to cause an E_NOTICE instead of an E_WARNING? That would > make this less annoying for old code. I don't know whether I think this > worth doing or not, I just want to point out the possibility. >
I like this idea and have updated the pull request to ignore the "Type $param = null" case, so the deprecation should now just catch the "definitely" incorrect signatures. So to summarize the current state: function test($foo = "bar", $baz) {} // Deprecated: Required parameter $baz follows optional parameter $foo function test(Abc $foo = null, $baz) {} // No warnings, works fine! With that adjustment made, are there any further concerns about this change? Regards, Nikita
  108405
February 5, 2020 12:15 guilliam.xavier@gmail.com (Guilliam Xavier)
Hi,

On Wednesday, February 5, 2020, Nikita Popov ppv@gmail.com> wrote:
> > > I like this idea and have updated the pull request to ignore the "Type > $param = null" case, so the deprecation should now just catch the > "definitely" incorrect signatures. > > So to summarize the current state: > > function test($foo = "bar", $baz) {} > // Deprecated: Required parameter $baz follows optional parameter $foo > > function test(Abc $foo = null, $baz) {} > // No warnings, works fine! > > With that adjustment made, are there any further concerns about this > change?
Can you please just clarify which of the following will emit a deprecation? function f1($a = null, $b) {} function f2(A $a = null, $b) {} function f3(?A $a = null, $b) {} (I think f1 will, f2 won't, but f3?) Thanks
> > Regards, > Nikita >
-- Guilliam Xavier
  108410
February 6, 2020 11:40 nikita.ppv@gmail.com (Nikita Popov)
On Wed, Feb 5, 2020 at 1:15 PM Guilliam Xavier xavier@gmail.com>
wrote:

> Hi, > > On Wednesday, February 5, 2020, Nikita Popov ppv@gmail.com> wrote: >> >> >> I like this idea and have updated the pull request to ignore the "Type >> $param = null" case, so the deprecation should now just catch the >> "definitely" incorrect signatures. >> >> So to summarize the current state: >> >> function test($foo = "bar", $baz) {} >> // Deprecated: Required parameter $baz follows optional parameter $foo >> >> function test(Abc $foo = null, $baz) {} >> // No warnings, works fine! >> >> With that adjustment made, are there any further concerns about this >> change? > > > Can you please just clarify which of the following will emit a deprecation? > > function f1($a = null, $b) {} > function f2(A $a = null, $b) {} > function f3(?A $a = null, $b) {} > > (I think f1 will, f2 won't, but f3? >
f1 will, f2 won't, f3 also won't. f3 could technically emit one, but I'm not sure it's worth having a special case of a special case for this. Nikita