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

TokenPolyfill tries to construct itself with an id which is a string #974

Closed
phil-davis opened this issue Jan 10, 2024 · 5 comments
Closed

Comments

@phil-davis
Copy link
Contributor

I updated to PhpParser https://github.com/nikic/PHP-Parser/releases/tag/v5.0.0

When I run phpunit in one repo, I get:

$ make test-php-unit
php -d zend.enable_gc=0 ../../lib/composer/bin/phpunit --configuration ./phpunit.xml --testsuite unit
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.3-4ubuntu2.19 with Xdebug 2.9.2
Configuration: ./phpunit.xml

id is not an int
/home/phil/git/owncloud/core/lib/composer/nikic/php-parser/lib/PhpParser/Internal/TokenPolyfill.php:204:
string(16) "T_NAME_QUALIFIED"
the value is: T_NAME_QUALIFIED
Argument 1 passed to PhpParser\Internal\TokenPolyfill::__construct() must be of the type int, string given, called in /home/phil/git/owncloud/core/lib/composer/nikic/php-parser/lib/PhpParser/Internal/TokenPolyfill.php on line 207
make: *** [Makefile:57: test-php-unit] Error 2

Related issue https://github.com/owncloud/files_classifier/issues/847 (sorry, that is a private repo)

Note: I added some debug lines in https://github.com/nikic/PHP-Parser/blob/master/lib/PhpParser/Internal/TokenPolyfill.php
And discovered that the constant \T_NAME_QUALIFIED is just becoming the literal string "T_NAME_QUALIFIED", when it should be some number, like in https://github.com/nikic/PHP-Parser/blob/master/lib/PhpParser/Parser/Php7.php
public const T_NAME_QUALIFIED = 393;

I don't see where TokenPolyfill.php includes that Php7.php

Is there something I need to do around the environment of PHP-parser, or does the code of TokenPolyfill.php need to include Php7.php and use it?

@nikic
Copy link
Owner

nikic commented Jan 10, 2024

This means you are using some other library that has buggy token emulation. I'll have to add an extra check to

// PHP-Parser might be used together with another library that also emulates some or all
to verify that the tokens have integer values and throw an early error in that case.

@phil-davis
Copy link
Contributor Author

This might be an issue with phpunit v9 and PHP 7.x - I haven't dug deeply into it yet.
Maybe it needs some adjustment to be able to run successfully with PHP-parser v5?

@nikic
Copy link
Owner

nikic commented Jan 10, 2024

I don't think this is related to phpunit. Try grepping for T_NAME_QUALIFIED in your vendor/ directory, which should hopefully show which library defines the constant.

@xabbuh
Copy link

xabbuh commented Jan 10, 2024

could be related to an issue that is addressed by phpDocumentor/TypeResolver#197

@phil-davis
Copy link
Contributor Author

could be related to an issue that is addressed by phpDocumentor/TypeResolver#197

That PR fixes this issue. See my comment phpDocumentor/TypeResolver#197 (comment)

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

No branches or pull requests

3 participants