-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
TokenPolyfill issue on PHP 7.4 platform #981
Comments
@llaville I have opened a issue on the PHPCS repo. maybe you can give more information about your use-case there, so jrfnl can decide whether there is something todo or not. I just wanted to raise awareness and cannot add more than that. |
@staabm Thanks but I don't think it come from PHPCS. I've investigated by debugging code analysed with TokenPolyfill, and there is an issue inside ! |
I've implemented a check to detect broken libraries like this a while ago (ff095c3) but never released it. It is now released and will hard error early on. |
@nikic FYI BTW I've put some debugging steps on TokenPolyfill
Code Analysed was $code = <<<CODE
<?php
declare(strict_types=1);
namespace Test\Sub;
class TestClass {
public function test() {}
}
CODE; When namespace is found
|
Confirmed by running package unit tests with PHP-Parser 5.0.1
|
But does that solve the problem ? As far as I can see, that just moves the problem around and doesn't solve anything... |
Answer is into official documentation https://github.com/nikic/PHP-Parser/blob/master/doc/component/Lexer.markdown So no solution on my use case |
@llaville This refers to something completely unrelated. That point is exactly the same on PHP-Parser 4.0. The problem here is that PHP-Parser and PHP_CodeSniffer are not compatible with each other. You currently cannot use both at the same time. |
But the issue still exists even if I removed PHP_CodeSniffer from context ! |
@jrfnl It doesn't solve the problem, but it provides a clear error message. It's impossible to "solve" this problem in PHP-Parser, because the requirement for integer token IDs is imposed by PHP itself. It's something I could avoid in my own TokenPolyfill on older versions, but on PHP 8 the native The only way I can avoid this requirement is by not using the global token constants at all, and instead redefining all token constants myself. I considered doing this (specifically to avoid this kind of problem), but opted not to do so, because I thought there was more value in sticking with PHP's own token format. In any case, it's not something I can change anymore. |
I've just found something strange. Need to investigate more again. On my fork version of But when I run same tests with phpunit installed as a dev dependency, I got no errors. |
That's interesting. I've been trying and failing to reproduce this problem with the dev dependency. With the phar file I see it as well. |
Just to avoid to put it on this thread, I've publish my PHPUnit tests comparaison on my PR at composer-unused/symbol-parser#133 (comment) |
Ah, it looks like the actual problem is |
The phar contains version 1.6.1, while https://github.com/phpDocumentor/TypeResolver/releases/tag/1.7.4 is the version with php-parser 5 compatibility. |
Good catch @nikic :) (because it use the PHPUnit phar copy : https://github.com/shivammathur/setup-php/blob/main/dist/index.js#L969) |
Nor I on the PHP_CodeSniffer side as PHPCS has used the string value token polyfills since its early days (~2006) and changing that now would be a breaking change and considering how many external standards there are, not one I really want to contemplate. Historical context: as the actual value of the PHP native token constants changes depending on the PHP version, polyfilling to the real value was not an option, so at the time (well before my time), the choice was made to polyfill to string values which would never get into a conflict with the PHP native token values. @nikic @llaville Regarding use in combination with PHPUnit - also see sebastianbergmann/php-code-coverage#1025 |
Might depend on which PHPUnit (PHAR) version is being used. The PHARs will have a fixed version of |
It's not really obvious to me what backwards compatibility break you are concerned about here: These tokens will already be defined with integer values on newer PHP version, so code already has to handle that just fine. Unless people are using But in any case, it doesn't look like the usage in PHP_CodeSniffer is problematic in practice anyway, as it shouldn't be used at the same time as PHP-Parser. The PHP_CodeSniffer mention here was a red herring. |
Considering the inventive code I've seen over the years, I wouldn't put it passed people...
Agreed. As long as neither PHPCS nor PHP-Parser has an |
Agree, as Nikita already said. But as I used the latest version 9.6.16 of PHPUnit (that support PHP 7.4) which include only version |
I filed sebastianbergmann/phpunit#5712 to check whether it's possible to update the dependency in the phar. But for your purposes, just switching to use vendor/bin/phpunit is probably the best fix for now :) |
@nikic Already on way ;-) composer-unused/symbol-parser#133 (comment) PS: Solved (see https://github.com/composer-unused/symbol-parser/actions/runs/7996055440) |
Hello,
I've worked today to make a package compatible with both PHP-Parser 4.18 and 5.0
I've detected an issue on (I know old platform PHP 7.4, but this package is still compatible PHP 7). Here are the details of my analysis
When PHP-Parser 5.0.0 is installed with PHP_CodeSniffer (3.9.0 in my situation), I got a
TypeError
Version 5.0 is supposed to be compatible with PHP 7.4 min (see https://github.com/nikic/PHP-Parser/blob/v5.0.0/composer.json#L16-L17)
But :
T_NAME_QUALIFIED
https://github.com/nikic/PHP-Parser/blob/v5.0.0/lib/PhpParser/Internal/TokenPolyfill.php#L200 was introduced on PHP 8.0.0beta1T_NAME_RELATIVE
https://github.com/nikic/PHP-Parser/blob/v5.0.0/lib/PhpParser/Internal/TokenPolyfill.php#L198 was introduced on PHP 8.0.0beta1T_NAME_FULLY_QUALIFIED
https://github.com/nikic/PHP-Parser/blob/v5.0.0/lib/PhpParser/Internal/TokenPolyfill.php#L196 was introduced on PHP 8.0.0beta1Reason is PHPCS define these tokens as string.
And TokenPolyfill first argument of class constructor is
int
Hope my explains are enough clear ?
The text was updated successfully, but these errors were encountered: