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 | Tokenizer/PHP: add support for nullsafe object operator #3046

Merged
merged 1 commit into from
Sep 1, 2020

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 6, 2020

This PR addresses the tokenizer changes needed for #3040. Once this PR has been merged, the sniff specific changes will be pulled with a PR per sniff.

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 the PHPCS Tokenizers\PHP class.

This commit:

  • Defines the token constant for PHP < 8.0.
  • Adds a backfill for the nullsafe object operator for PHP < 8.0 to the PHP tokenizer.
  • Adds the token to applicable token lists in the PHP and base tokenizer class, like the one used in the short array re-tokenization.
  • Adds perfunctory unit tests for the nullsafe object operator backfill.
  • Adds a unit test using the operator to the tokenizer tests for the short array re-tokenization.

Refs:

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 the PHPCS `Tokenizers\PHP` class.

This commit:
* Defines the token constant for PHP < 8.0.
* Adds a backfill for the nullsafe object operator for PHP < 8.0 to the PHP tokenizer.
* Adds the token to applicable token lists in the PHP and base tokenizer class, like the one used in the short array re-tokenization.
* Adds perfunctory unit tests for the nullsafe object operator backfill.
* Adds a unit test using the operator to the tokenizer tests for the short array re-tokenization.

Refs:
* https://wiki.php.net/rfc/nullsafe_operator
* php/php-src@9bf1198
@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 7, 2020

@gsherwood Two FYIs:

  1. The nightly build tests failure is not due to this PR, but to PHP 8 changes related to named identifiers as one token - see PHP 8.0 | Proposal for handling "namespaced names as single token" #3041
  2. While this PR does introduce a new token, that token is a backfill for a PHP native token, not a PHPCS specific one, so with that in mind, I believe this PR can be milestoned for 3.5.6.

@gsherwood gsherwood added this to the 3.5.7 milestone Aug 31, 2020
@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Aug 31, 2020
gsherwood added a commit that referenced this pull request Sep 1, 2020
@gsherwood gsherwood merged commit f09e28a into squizlabs:master Sep 1, 2020
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Sep 1, 2020
@gsherwood
Copy link
Member

Thanks. I think I've now unblocked those other PRs you have.

@jrfnl jrfnl deleted the feature/php-8-nullsafe-operator branch September 1, 2020 23:05
@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 1, 2020

@gsherwood One set of them for sure, though I also have sets ready for the union types and constructor property promotion changes.
I'll send in the ones which were blocked by this PR in a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

2 participants