nikic / PHP-Parser

A PHP parser written in PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

phil-davis opened this issue · comments

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?

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.

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?

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.

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

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)