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

PHP-Scoper 0.18.12 breaks PHAR for PHPUnit 8.5 on PHP 7.2 #5855

Closed
sebastianbergmann opened this issue Jun 7, 2024 · 8 comments · Fixed by humbug/php-scoper#1044 or humbug/php-scoper#1049
Assignees
Labels
installation/phar version/8 Something affects PHPUnit 8

Comments

@sebastianbergmann
Copy link
Owner

After updating PHP-Scoper from 0.18.11 to 0.18.12 in a3d40a3, the PHAR for PHPUnit 8.5 does not work with PHP 7.2:

PHP Parse error:  syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in phar:///home/runner/work/phpunit/phpunit/build/artifacts/phpunit-snapshot.phar/phpunit/Framework/MockObject/Generator.php on line 736
@sebastianbergmann sebastianbergmann added installation/phar version/8 Something affects PHPUnit 8 labels Jun 7, 2024
@sebastianbergmann sebastianbergmann self-assigned this Jun 7, 2024
@sebastianbergmann
Copy link
Owner Author

@theofidry Before I dig into this, is there anything that would be obvious to you that might explain this? Thanks!

@mfn
Copy link

mfn commented Jun 7, 2024

Maybe this from the release https://github.com/humbug/php-scoper/releases/tag/0.18.12

Upgrade to PHP-Parser v5 (humbug/php-scoper#1025)

https://github.com/nikic/PHP-Parser?tab=readme-ov-file#php-parser says:

Documentation for version 5.x (current; for running on PHP >= 7.4; for parsing PHP 7.0 to PHP 8.3, with limited support for parsing PHP 5.x).

So you can't run this on PHP < 7.4 I guess? 🤔

@sebastianbergmann
Copy link
Owner Author

@mfn PHP-Scoper requires a newer version of PHP, yes. But that does not have to mean that the modified code no longer works with PHP 7.2.

@theofidry
Copy link
Contributor

Aside from the PHP-Parser upgrade I don't see anything that could cause this :/ Do you have the offending code by any chance? I can take a look at it

@sebastianbergmann
Copy link
Owner Author

$ git clone git@github.com:sebastianbergmann/phpunit.git
$ cd phpunit
$ git checkout 8.5
$ ant phar-snapshot
$ php-72 build/artifacts/phpunit-snapshot.phar

Parse error: syntax error in phar:///usr/local/src/phpunit/build/artifacts/phpunit-snapshot.phar/phpunit/Framework/MockObject/Generator.php on line 736
$ phar extract -f /usr/local/src/phpunit/build/artifacts/phpunit-snapshot.phar
$ php-72 -l phpunit/Framework/MockObject/Generator.php

Parse error: syntax error in phpunit/Framework/MockObject/Generator.php on line 736
Errors parsing phpunit/Framework/MockObject/Generator.php

Attached is the result of ant phar-snapshot for the current state of the 8.5 branch.

phpunit-snapshot.phar.tar.gz

@theofidry
Copy link
Contributor

Ok I got a small reproducer within the PHP-Scoper test suite, will look more into it

theofidry added a commit to humbug/php-scoper that referenced this issue Jun 16, 2024
This PR introduces a `php-version` to the configuration file and as command options for the `add-prefix` and `inspect` command (e.g. have `--php-version=7.2`).

The PHP version provided is used to configure the underlying PHP-Parser Parser and Printer. This will not affect
the PHP internal symbols used by PHP-Scoper (i.e. `mb_str_pad` will be understood as an internal function, even if the PHP version configured is <8.3). However, this will affect what code can be parsed and how the code will be printed.

If no PHP version is used, the host version will be used, i.e. executing it with PHP 8.4 will
result in PHP 8.4 being used as the PHP version. 

This should allow to forcefully fix sebastianbergmann/phpunit#5855.
theofidry added a commit to humbug/php-scoper that referenced this issue Jun 16, 2024
See the discussion in nikic/PHP-Parser#1007.

This should fix sebastianbergmann/phpunit#5855 although this may result in more ugly code formatting than desired. For this reason the default printer version is 7.2 rather than 5.3 as it would make the code too otherwise.
@theofidry
Copy link
Contributor

theofidry commented Jun 16, 2024

@sebastianbergmann this should be fixed in 0.18.14. If it is not, for this specific build, you can use --php-version="7.2"

@sebastianbergmann
Copy link
Owner Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installation/phar version/8 Something affects PHPUnit 8
Projects
None yet
3 participants