-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix mis-identification of 'readonly' keyword #3773
Fix mis-identification of 'readonly' keyword #3773
Conversation
Using the following test code on https://onlinephp.io/ <?php
function readonly() {
print "yes\n";
}
readonly();
readonly ();
readonly /* comment */ (); I get expected results on PHP versions However, all versions of PHP 8.1.x produce a parse error on the last line with this code sample. Do we need to add any special handling for PHP 8.1.x to this |
44f79f4
to
6385006
Compare
@jrfnl as far as I know, this change should make all the automated tests pass. I expect that may help with the triage process for other pull requests. I don't know where this pull request fits in the list of what to review. I'm highlighting this to hopefully help, but please feel free to ignore this comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fredden and me looked at this PR in detail together and this needs more work.
Findings:
- The current fix will break on PHP 8.2 DNF.
- More tests needs to be added.
Basically, we need to make sure that all tests which are included in this PHP Core commit are also included in the PHPCS Tokenizer BackfillReadonlyTest
file and that those tests pass correctly: php/php-src@08b7539
Also, in the original implementation of the backfill, the situation where a comment would be between the readonly
and the (
for function declarations/calls was not taken into account.
This is not handled in PHP Core, however, the PHPCS token stream should still be consistent for this as it will otherwise break sniffs which specifically look for the T_READONLY
token.
As for DNF: that doesn't need to be handled in this PR, but at the very least, the readonly
keyword tokenization should not break on it, while it currently would.
Related: in #3667 there are some comments/analysis about the change in the readonly
tokenization in PHP Core and how it relates to DNF.
I look forward to a next iteration on this PR.
For reference - these are some older PRs related to the tokenization backfill for |
3053135
to
f324e5c
Compare
@jrfnl is there anything I can do to help progress this? |
An adjusted version of this PR has been merged in PHPCSStandards/PHP_CodeSniffer#34 |
Superseded by PHPCSStandards/PHP_CodeSniffer#34 |
FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release. As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo). |
The test suite for this package is failing on PHP 8.2. This seems to be due to a mis-identification of the
readonly
keyword when used as a function name. For example, https://github.com/squizlabs/PHP_CodeSniffer/actions/runs/4318800044/jobs/7537540753.This pull request fixes that test failure.
I have tested this with PHP version 8.2.3. I also noticed that the test case "testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens" seems to have been in the wrong category within the test suite.