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

Syntax error, unexpected T_MATCH #196

Closed
rieschl opened this issue Jul 31, 2020 · 13 comments · Fixed by #199
Closed

Syntax error, unexpected T_MATCH #196

rieschl opened this issue Jul 31, 2020 · 13 comments · Fixed by #199
Assignees
Labels
bug dependencies Pull requests that update a dependency file enhancement
Milestone

Comments

@rieschl
Copy link
Contributor

rieschl commented Jul 31, 2020

We encounter some strange behavior lately. On some projects/libraries, the checker returns the following error:

$ vendor/bin/composer-require-checker
ComposerRequireChecker 2.1.0@0c66698d487fcb5c66cf07108e2180c818fb2e72

In ParserAbstract.php line 315:

  Syntax error, unexpected T_MATCH on line 15


check [--config-file CONFIG-FILE] [--ignore-parse-errors] [--] [<composer-json>]

It seems to be somehow related to PHPunit when it is installed as non-dev dependency.
Psalm also had a similar problem but fixed it already: vimeo/psalm#3901

The error disappears when I remove the extends Match from \PHPUnit\Framework\MockObject\Builder\ParametersMatch lins 15.

Anyone has a clue what's going on there?

@Ocramius
Copy link
Collaborator

Possibly new PHP-Parser running with PHP 8.x compat? match became a keword since php:8-alpha

@rieschl
Copy link
Contributor Author

rieschl commented Jul 31, 2020

Hmm, sorry I forgot to mention the versions. PHP 7.4.7, phpunit/phpunit: 9.2.6, maglnet/composer-require-checker: 2.1.0.

When checking the version, I discovered, that this bug seems to be gone in PHP 7.4.8.
Let me check that and I'll come back with the results.

@rieschl
Copy link
Contributor Author

rieschl commented Jul 31, 2020

ok... it's not related to the PHP version, but version of nikic/php-parser. There is no error with version 4.6.*, only with the current 4.7.*.
If I interpret this correctly, that's not a problem with this library but with php-parser being too strict and/or phpunit which uses a keyword which will be reserved in PHP8, right?
psalm "resolved" this problem by restricting php-parser versions.

Edit: Its already a known issue there: nikic/PHP-Parser#690

@Ocramius
Copy link
Collaborator

I don't think the version should be restricted there: rather, the parser being used should be configured.

I think it's configured correctly here:

$sourcesASTs = new LocateASTFromFiles((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $errorHandler);

Probably need to report an issue upstream.

@rieschl rieschl changed the title Syntax error, unexpected T_MATCH on line 15 in some libraries Syntax error, unexpected T_MATCH Jul 31, 2020
@rieschl
Copy link
Contributor Author

rieschl commented Jul 31, 2020

Probably need to report an issue upstream.

There is, already: nikic/PHP-Parser#690

@andrewmy
Copy link

andrewmy commented Sep 1, 2020

As commented by @nikic in that issue,

It should now be possible to control the emulation level by passing ['phpVersion' => '7.4'] to the emulative lexer.

So still needs a fix here.

@nikic
Copy link

nikic commented Sep 1, 2020

You might also just want to not use emulation at all for this use case (i.e. parse for the PHP version you're running on).

@andrewmy
Copy link

andrewmy commented Sep 1, 2020

@nikic do you mean passing new Lexer() to the ParserFactory?

@rieschl
Copy link
Contributor Author

rieschl commented Sep 14, 2020

Follow-up: It works for me now with 2.1.0. It seems that php-parser uses the running PHP version to parse the code.

@rieschl rieschl closed this as completed Sep 14, 2020
@Baptouuuu
Copy link

Hi,

I still have the problem with nikic/php-parser 4.9.1 and maglnet/composer-require-checker 2.1.0. @rieschl did you change anything else to make it work ?

@rieschl
Copy link
Contributor Author

rieschl commented Sep 14, 2020

no, I did not change anything. which php version do you use?

@Baptouuuu
Copy link

7.4

@rieschl
Copy link
Contributor Author

rieschl commented Sep 14, 2020

You're right. My error didn't disappear because of a new php-parser version but because PHPUnit removed the offending class: sebastianbergmann/phpunit@b57cd45
match is a reserved keyword in PHP8 (it's a function/control structure there [src]) so they have to get rid of it anyway. If I checked correctly that change was in 9.3.0, so you can try to update to the latest PHPUnit and see if the error goes away.
Of course, if you use PHP8 stuff somewhere else that won't help much.

@rieschl rieschl reopened this Sep 14, 2020
@Ocramius Ocramius added this to the 2.2.0 milestone Oct 1, 2020
@Ocramius Ocramius self-assigned this Oct 1, 2020
@Ocramius Ocramius added bug dependencies Pull requests that update a dependency file enhancement labels Oct 1, 2020
@Ocramius Ocramius modified the milestones: 2.2.0, 3.0.0 Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dependencies Pull requests that update a dependency file enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants