Skip to content

PHP 8.0: new PHPCompatibility.FunctionDeclarations.RemovedOptionalBeforeRequiredParam sniff#1165

Merged
wimg merged 1 commit intodevelopfrom
php-8.0/new-removedoptionalbeforerequiredparam-sniff
Jul 18, 2020
Merged

PHP 8.0: new PHPCompatibility.FunctionDeclarations.RemovedOptionalBeforeRequiredParam sniff#1165
wimg merged 1 commit intodevelopfrom
php-8.0/new-removedoptionalbeforerequiredparam-sniff

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 11, 2020

PHP 8.0 will deprecate required function parameters being placed after optional ones.

Declaring a required parameter after an optional one is deprecated. As an
exception, declaring a parameter of the form "Type $param = null" before
a required one continues to be allowed, because this pattern was sometimes
used to achieve nullable types in older PHP versions.

    function test($a = [], $b) {}       // Deprecated
    function test(Foo $a = null, $b) {} // Allowed

Refs:

This new sniff detects this.

Includes unit tests.

Related to #809

…BeforeRequiredParam` sniff

PHP 8.0 will deprecated required function parameters being placed after optional ones.

> Declaring a required parameter after an optional one is deprecated. As an
>  exception, declaring a parameter of the form "Type $param = null" before
>  a required one continues to be allowed, because this pattern was sometimes
>  used to achieve nullable types in older PHP versions.
> ```php
>     function test($a = [], $b) {}       // Deprecated
>     function test(Foo $a = null, $b) {} // Allowed
> ```

Refs:
* https://github.com/php/php-src/blob/69888c3ff1f2301ead8e37b23ff8481d475e29d2/UPGRADING#L145-L151
* php/php-src@3b08f53

This new sniff detects this.

Includes unit tests.
@jrfnl jrfnl force-pushed the php-8.0/new-removedoptionalbeforerequiredparam-sniff branch from 063b620 to a4e8486 Compare July 14, 2020 11:43
@wimg wimg merged commit 9d27dd8 into develop Jul 18, 2020
@wimg wimg deleted the php-8.0/new-removedoptionalbeforerequiredparam-sniff branch July 18, 2020 22:36
@ShkiperMe
Copy link

Hi guys,

I've downloaded the dev version of the PHPCompatibility library and installed all dependencies with the composer but it seems that the current rule doesn't work for me.
I have a file that contains functions with optional parameters before the required and I execute a code sniffer to test it(vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.0 PROGECT_PATH), but I do not receive a notification about the issue.
Could you please help me to configure the lib property and detect all issues related to the PHP 8 compatibility?

@jrfnl
Copy link
Member Author

jrfnl commented Apr 27, 2022

@ShkiperMe This is a closed PR, so please don't use it to ask for help on an unrelated issue (installation issues).

There is an issue open with some pointers on how to get the develop version up and running while we are working on getting PHPCompatibility 10.0.0 released: #1312

If that doesn't help and you have a genuine bug report, please open an issue with a code sample so we can try and reproduce the issue.

P.S.: Please don't (mis)gender maintainers. Not a good look.

@ShkiperMe
Copy link

@jrfnl
Thank you a lot for your help.
I'm terribly sorry for my inappropriate question

@jrfnl
Copy link
Member Author

jrfnl commented Apr 27, 2022

@ShkiperMe Not an inappropriate question, just not the right place to ask it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants