Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.0 : NewOperators account for nullsafe object operator #1210

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Aug 17, 2020

PHP 8.0: NewOperators: detect new nullsafe object operator

PHP 8 introduces a new object chaining operator ?-> which short-circuits moving to the next expression if the left-hand side evaluates to null.

This operator can not be used in write-context, but that is not the concern of this sniff.

Refs:

Includes unit test.

NewOperators: improve grammar of the error message

PHP 8.0: NewConstants: add new T_NULLSAFE_OBJECT_OPERATOR constant

Ref: https://wiki.php.net/rfc/nullsafe_operator

...and exclude it from triggering when running PHPCompatibility over its own code.

Related to #809

@jrfnl jrfnl added enhancement PR: quick merge PR only contains relatively simple changes PR: ready for review labels Aug 17, 2020
@jrfnl jrfnl added this to the 10.0.0 milestone Aug 17, 2020
@jrfnl jrfnl requested a review from wimg August 17, 2020 00:28
PHP 8 introduces a new object chaining operator `?->` which short-circuits moving to the next expression if the left-hand side evaluates to `null`.

This operator can not be used in write-context, but that is not the concern of this sniff.

Refs:
* https://wiki.php.net/rfc/nullsafe_operator
* php/php-src#5619
* php/php-src@9bf1198

Includes unit test.
Ref: https://wiki.php.net/rfc/nullsafe_operator

...and exclude it from triggering when running PHPCompatibility over its own code.
@jrfnl jrfnl force-pushed the php-8.0/newoperators-account-for-nullsafe-object-operator branch from 9c8c43a to 04b3517 Compare August 18, 2020 16:02
@jrfnl
Copy link
Member Author

jrfnl commented Aug 19, 2020

Ok, so the build failing appears to be due to an obscure bug in Xdebug 2.9.6. Same problem as we had the other week when I changed a coverage build from PHP 7.3 to PHP 7.2 to get round it.

The weirdest thing is that it only occurs with the NewOperators sniff, while similar code is also used in the NewKeywords, NewLanguageConstructs, NewTypeCasts and RemovedTypeCasts sniffs.

Note: this is a test-only problem as for the tests each sniff is instantiated numerous times, while in a "normal" PHPCS run, each sniff is only instantiated once, so the problem would not occur in a "normal" PHPCS run.

I've tried my damnest to think of a work-around for the time being to allow the build to pass, but I honestly can't think of one without making the code very weird indeed, while it may still not work.

@wimg wimg merged commit 4be7bc9 into develop Aug 23, 2020
@wimg wimg deleted the php-8.0/newoperators-account-for-nullsafe-object-operator branch August 23, 2020 15:45
@jrfnl jrfnl removed PR: quick merge PR only contains relatively simple changes PR: ready for review labels Aug 23, 2020
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.

None yet

2 participants