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 8.1-beta1 causes fatal error when running from Phar #4740

Closed
jrfnl opened this issue Jul 21, 2021 · 9 comments
Closed

PHP 8.1-beta1 causes fatal error when running from Phar #4740

jrfnl opened this issue Jul 21, 2021 · 9 comments
Assignees
Labels
type/change-in-php-requires-adaptation A change in PHP requires a change so that existing PHPUnit functionality continues to work

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Jul 21, 2021

Q A
PHPUnit version 9.5.7
PHP version 8.1.0-beta1
Installation Method PHAR

Summary

When I try to run any test suite on PHP 8.1.0-beta1 using the PHPUnit phar, it results in:

PHP 8.1.0beta1 (cli) (built: Jul 20 2021 17:20:01) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.0-dev, Copyright (c) Zend Technologies

Fatal error: Could not check compatibility between PHPUnit\PharIo\Manifest\AuthorCollection::getIterator(): PHPUnit\PharIo\Manifest\AuthorCollectionIterator and IteratorAggregate::getIterator(): Traversable, because class PHPUnit\PharIo\Manifest\AuthorCollectionIterator is not available in phar://phars/phpunit-9.5.7.phar/phar-io-manifest/values/AuthorCollection.php on line 33

Current behavior

I tested with the same PHPUnit/PHP combination against various test suites. All resulted in the above error. No tests are run.

How to reproduce

  • Download the PHPUnit phar.
  • Place it somewhere where it is within the system path.
  • Run it from the root directory of any project which has tests, like the root directory of the PHPUnit repo ;-)

Expected behavior

For the tests to run 😉

@jrfnl jrfnl added the type/bug Something is broken label Jul 21, 2021
@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 21, 2021

Note: I've opened this issue here as the error notice indicates it is a problem with the Phar missing a file.

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Jul 22, 2021

The PHAR for PHPUnit 9.5.7 was built with phar-io/manifest 2.0.1. Since then, version 2.0.3 of that library has been released which contains a fix for the PHP 8.1 deprecation notices.

As you can see here, the PHAR built from the current state of 9.5 fails for a different (but similar) reason that I shall address shortly.

Thank you for bringing this to my attention. We now test the PHAR against all supported versions of PHP instead of just one.

@sebastianbergmann sebastianbergmann added type/change-in-php-requires-adaptation A change in PHP requires a change so that existing PHPUnit functionality continues to work and removed type/bug Something is broken labels Jul 22, 2021
@sebastianbergmann sebastianbergmann self-assigned this Jul 22, 2021
@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Jul 22, 2021

The PHAR for PHPUnit 9.5.7 was built with phar-io/manifest 2.0.1. Since then, version 2.0.3 of that library has been released which contains a fix for the PHP 8.1 deprecation notices.

Oh-kay, this is more complex than originally thought. The deprecation notices are fixed in phar-io/manifest 2.0.3, but PHPAB's topological sort of code units puts the import of AuthorCollection before AuthorCollectionIterator leading to

require __DIR__ . '/../vendor/phar-io/manifest/src/values/AuthorCollection.php';
require __DIR__ . '/../vendor/phar-io/manifest/src/values/AuthorCollectionIterator.php';

which results in

Fatal error: Could not check compatibility between
PharIo\Manifest\AuthorCollection::getIterator(): PharIo\Manifest\AuthorCollectionIterator
and IteratorAggregate::getIterator(): Traversable, because class
PharIo\Manifest\AuthorCollectionIterator is not available in /path/to/manifest/src/values/AuthorCollection.php on line 31

Changing

require __DIR__ . '/../vendor/phar-io/manifest/src/values/AuthorCollection.php';
require __DIR__ . '/../vendor/phar-io/manifest/src/values/AuthorCollectionIterator.php';

to

require __DIR__ . '/../vendor/phar-io/manifest/src/values/AuthorCollectionIterator.php';
require __DIR__ . '/../vendor/phar-io/manifest/src/values/AuthorCollection.php';

fixes this.

However, this certainly will break at some point in the future when additional compile-time checks are added to PHP. The only solution I see is to stop using a static autoloader for the PHAR. This was required in the past for preventing errors in environments where users run PHPUnit from a PHAR in a project where (a different version of) PHPUnit is also installed using Composer. This was before we had scoped PHARs.

Regarding the topological sorting of code units performed by PHPAB: that is a different topic (for a different repository). I suspect that PHPAB's sorter does not look at return type declarations (yet) as it should have otherwise detected the cyclic dependency between AuthorCollection before AuthorCollectionIterator.

@sebastianbergmann
Copy link
Owner

@nikic ping to let you know that these recent changes in PHP 8.1 caused an issues that was unexpected, at least to me. Maybe this should be noted in the upgrading notes?

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Jul 22, 2021

Current status: PHARs built from 8.5, 9.5, and master work on PHP 8.1. However, building the PHAR using PHP 8.1 does not work. This is what causes the build failures here and here.

When support for PHPUnit 8.5 for newer PHP versions was decided, we forgot to backport build pipeline improvements to the 8.5 branch. I have opened #4741 to remedy that.

@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 22, 2021

Thanks @sebastianbergmann for your swift action on this and the detailed analysis.

I'd seen the PHP 8.1 update commits in Phar.io before I opened this issue, but as they didn't seem to involve the classes mentioned in the error, I had a feeling this was going to be more complex than just updating.

@sebastianbergmann
Copy link
Owner

I have raised a question about this on the PHP development mailinglist.

@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 23, 2021

Setting error_reporting to -1 for the Phar build test runs showed me two more PHP 8.1 issues. Reported in: box-project/box#557

@sebastianbergmann
Copy link
Owner

As of d7258e0, PHPUnit now errors out when it detects that it was invoked from a PHAR but its code is autoloaded from a different source such as a Composer-managed installation.

sebastianbergmann added a commit that referenced this issue Jul 26, 2021
Instead of replacing static loading with autoloading we now combine the best of both worlds. The PHAR now loads all sourcecode files bundled in it on startup (again), but assisted by an autoloader so that PHP's compiler can find code units that have not been loaded yet for perming method compatibility checks, for instance.
jrfnl added a commit to jrfnl/ReflectionCommon that referenced this issue Jul 31, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Ref: sebastianbergmann/phpunit#4740
jrfnl added a commit to jrfnl/ReflectionCommon that referenced this issue Jul 31, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Ref: sebastianbergmann/phpunit#4740
jrfnl added a commit to jrfnl/ReflectionCommon that referenced this issue Jul 31, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Ref: sebastianbergmann/phpunit#4740
jrfnl added a commit to jrfnl/ReflectionCommon that referenced this issue Jul 31, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

And as this package is one of the dependencies for PHPUnit itself, we also need to tell Composer via `COMPOSER_ROOT_VERSION` to allow for this package as-is.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Refs:
* sebastianbergmann/phpunit#4740
* https://getcomposer.org/doc/articles/troubleshooting.md#dependencies-on-the-root-package
jrfnl added a commit to jrfnl/ReflectionCommon that referenced this issue Jul 31, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

And as this package is one of the dependencies for PHPUnit itself, we also need to tell Composer via `COMPOSER_ROOT_VERSION` to allow for this package as-is.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Refs:
* sebastianbergmann/phpunit#4740
* https://getcomposer.org/doc/articles/troubleshooting.md#dependencies-on-the-root-package
jrfnl added a commit to jrfnl/ReflectionCommon that referenced this issue Jul 31, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

And as this package is one of the dependencies for PHPUnit itself, we also need to tell Composer via `COMPOSER_ROOT_VERSION` to allow for this package as-is.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Refs:
* sebastianbergmann/phpunit#4740
* https://getcomposer.org/doc/articles/troubleshooting.md#dependencies-on-the-root-package
jrfnl added a commit to jrfnl/ReflectionCommon that referenced this issue Jul 31, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

And as this package is one of the dependencies for PHPUnit itself, we also need to tell Composer via `COMPOSER_ROOT_VERSION` to allow for this package as-is.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Refs:
* sebastianbergmann/phpunit#4740
* https://getcomposer.org/doc/articles/troubleshooting.md#dependencies-on-the-root-package
jrfnl added a commit to jrfnl/ReflectionDocBlock that referenced this issue Aug 1, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

And as this package is one of the dependencies for PHPUnit itself, we also need to tell Composer via `COMPOSER_ROOT_VERSION` to allow for this package as-is.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Refs:
* sebastianbergmann/phpunit#4740
* https://getcomposer.org/doc/articles/troubleshooting.md#dependencies-on-the-root-package
jrfnl added a commit to jrfnl/ReflectionDocBlock that referenced this issue Aug 1, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

And as this package is one of the dependencies for PHPUnit itself, we also need to tell Composer via `COMPOSER_ROOT_VERSION` to allow for this package as-is.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Refs:
* sebastianbergmann/phpunit#4740
* https://getcomposer.org/doc/articles/troubleshooting.md#dependencies-on-the-root-package
jrfnl added a commit to jrfnl/ReflectionDocBlock that referenced this issue Aug 1, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

And as this package is one of the dependencies for PHPUnit itself, we also need to tell Composer via `COMPOSER_ROOT_VERSION` to allow for this package as-is.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Refs:
* sebastianbergmann/phpunit#4740
* https://getcomposer.org/doc/articles/troubleshooting.md#dependencies-on-the-root-package
jrfnl added a commit to jrfnl/ReflectionDocBlock that referenced this issue Aug 1, 2021
The latest release of the PHPUnit Phar still contains an incompatibility with PHP 8.1-beta1 (and higher).

Using a Composer installed version of PHPUnit will not hit this incompatibility. However, installing via Composer does require to use the `--ignore-platform-reqs` option, for now, as `phpspec/prophecy`, one of PHPUnit's dependencies does not yet allow for installation on PHP 8.1.

And as this package is one of the dependencies for PHPUnit itself, we also need to tell Composer via `COMPOSER_ROOT_VERSION` to allow for this package as-is.

**Important**: Once PHPUnit 9.5.8 has been released, this commit should be reverted.

Refs:
* sebastianbergmann/phpunit#4740
* https://getcomposer.org/doc/articles/troubleshooting.md#dependencies-on-the-root-package
iamcal added a commit to iamcal/SQLParser that referenced this issue Mar 5, 2022
* detect when we've reached the end of input when lexing an unterminated string
* added a mode where we throw exceptions for invalid syntax
* added tests for invalid syntax, in both default and exception mode
* documented `$parser->throw_on_bad_syntax`
* get tests running again on php 8.1 (broken by sebastianbergmann/phpunit#4740)
michaelr0 pushed a commit to HandmadeWeb/buildamic that referenced this issue Mar 31, 2022
Resolve PHP Fatal error:  Cannot acquire reference to $GLOBALS in vendor/phpunit/phpunit/src/Util/Configuration.php on line 407 by requiring 8.5.14 or higher.
Bump minimum phpunit from 8.5.14 to 8.5.19 to address issues resolved in sebastianbergmann/phpunit#4740
Adjustments to Laravel Framework and PHPUnit min versions
Adjustments to GH Action's minimum Laravel Framework version.
Workflow adjustments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/change-in-php-requires-adaptation A change in PHP requires a change so that existing PHPUnit functionality continues to work
Projects
None yet
Development

No branches or pull requests

2 participants