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: support PHP8 magic constant dereferencing #3013

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jul 10, 2020

As of PHP 8, magic constants can be dereferenced, however, the square brackets are incorrectly tokenized as short array brackets instead of as "normal" square brackets.

Fixed by:

  • Adding a new $magicConstants array to the Util\Tokens calls.
  • Adding the $magicConstants to the allowed tokens for leaving the brackets alone in the Tokenizers\PHP class.

Includes adding unit tests for this section of the PHP::processAdditional() method.

I've added as many relevant syntaxes as I could come up with, but won't claim that the unit test case file covers every possible scenario. Should be a good start though.

Ref: https://wiki.php.net/rfc/variable_syntax_tweaks#constants_and_magic_constants

As of PHP 8, magic constants can be dereferenced, however, the square brackets are incorrectly tokenized as _short array_ brackets instead of as "normal" square brackets.

Fixed by:
* Adding a new `$magicConstants` array to the `Util\Tokens` calls.
* Adding the `$magicConstants` to the allowed tokens for leaving the brackets alone in the PHP Tokenizer class.

Includes adding unit tests for this section of the `PHP::processAdditional()` method.

I've added as many relevant syntaxes as I could come up with, but won't claim that the unit test case file covers every possible scenario. Should be a good start though.

Ref: https://wiki.php.net/rfc/variable_syntax_tweaks#constants_and_magic_constants
@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 12, 2020

Test build which includes PR #3014 which confirms that the build for this PR would pass on PHP 8/nightly: https://travis-ci.com/github/jrfnl/PHP_CodeSniffer/jobs/360290642

@gsherwood gsherwood added this to the 3.5.6 milestone Jul 20, 2020
gsherwood added a commit that referenced this pull request Jul 20, 2020
@gsherwood gsherwood merged commit bbb8dd3 into squizlabs:master Jul 20, 2020
@jrfnl jrfnl deleted the feature/php8-tokenizer-magic-constant-dereferencing branch July 20, 2020 22:37
@gsherwood
Copy link
Member

Thanks

@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 20, 2020

@gsherwood Should the new token array get a mention in the changelog ?

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

Successfully merging this pull request may close these issues.

2 participants