PHP 8.0 : NewOperators account for nullsafe object operator#1210
PHP 8.0 : NewOperators account for nullsafe object operator#1210
Conversation
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.
9c8c43a to
04b3517
Compare
|
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 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. |
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 tonull.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_OPERATORconstantRef: https://wiki.php.net/rfc/nullsafe_operator
...and exclude it from triggering when running PHPCompatibility over its own code.
Related to #809