Skip to content

Why phar stream is being unregistered? #21973

Closed
@kassner

Description

@kassner

Summary

The 2.3.1 release introduced the line stream_wrapper_unregister('phar'); in the app/boostrap.php. It's unclear why it was added, but it breaks a few external tools, like PHPStan.

Examples

/var/www/magento $ phpstan analyse --autoload-file=app/bootstrap.php -c dev/tools/phpstan/config.neon --level=max app/code/
PHP Warning:  include(): Unable to find the wrapper "phar" - did you forget to enable it when you configured PHP? in /var/www/magento/vendor/composer/ClassLoader.php on line 444

Warning: include(): Unable to find the wrapper "phar" - did you forget to enable it when you configured PHP? in /var/www/magento/vendor/composer/ClassLoader.php on line 444
PHP Warning:  include(): Unable to find the wrapper "phar" - did you forget to enable it when you configured PHP? in /var/www/magento/vendor/composer/ClassLoader.php on line 444

Warning: include(): Unable to find the wrapper "phar" - did you forget to enable it when you configured PHP? in /var/www/magento/vendor/composer/ClassLoader.php on line 444
PHP Warning:  include(phar:///usr/local/bin/phpstan/vendor/composer/../../src/DependencyInjection/ContainerFactory.php): failed to open stream: No such file or directory in /var/www/magento/vendor/composer/ClassLoader.php on line 444

Warning: include(phar:///usr/local/bin/phpstan/vendor/composer/../../src/DependencyInjection/ContainerFactory.php): failed to open stream: No such file or directory in /var/www/magento/vendor/composer/ClassLoader.php on line 444
PHP Warning:  include(): Failed opening 'phar:///usr/local/bin/phpstan/vendor/composer/../../src/DependencyInjection/ContainerFactory.php' for inclusion (include_path='/var/www/magento/generated/code:/var/www/magento/generated/code:/var/www/magento/vendor/magento/zendframework1/library:.:') in /var/www/magento/vendor/composer/ClassLoader.php on line 444

Warning: include(): Failed opening 'phar:///usr/local/bin/phpstan/vendor/composer/../../src/DependencyInjection/ContainerFactory.php' for inclusion (include_path='/var/www/magento/generated/code:/var/www/magento/generated/code:/var/www/magento/vendor/magento/zendframework1/library:.:') in /var/www/magento/vendor/composer/ClassLoader.php on line 444
string(44) "PHPStan\DependencyInjection\ContainerFactory"
PHP Fatal error:  Uncaught Error: Class 'PHPStan\DependencyInjection\ContainerFactory' not found in phar:///usr/local/bin/phpstan/src/Command/CommandHelper.php:73
Stack trace:
#0 phar:///usr/local/bin/phpstan/src/Command/AnalyseCommand.php(46): PHPStan\Command\CommandHelper::begin(Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Output\ConsoleOutput), Array, NULL, NULL, '/var/www/magent...', 'dev/tools/phpst...', 'max')
#1 phar:///usr/local/bin/phpstan/vendor/symfony/console/Command/Command.php(228): PHPStan\Command\AnalyseCommand->execute(Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Output\ConsoleOutput))
#2 phar:///usr/local/bin/phpstan/vendor/symfony/console/Application.php(831): _HumbugBox3fccee4f38a4\Symfony\Component\Console\Command\Command->run(Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox3fccee4f38a4\Symfony\Co in phar:///usr/local/bin/phpstan/src/Command/CommandHelper.php on line 73

Fatal error: Uncaught Error: Class 'PHPStan\DependencyInjection\ContainerFactory' not found in phar:///usr/local/bin/phpstan/src/Command/CommandHelper.php:73
Stack trace:
#0 phar:///usr/local/bin/phpstan/src/Command/AnalyseCommand.php(46): PHPStan\Command\CommandHelper::begin(Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Output\ConsoleOutput), Array, NULL, NULL, '/var/www/magent...', 'dev/tools/phpst...', 'max')
#1 phar:///usr/local/bin/phpstan/vendor/symfony/console/Command/Command.php(228): PHPStan\Command\AnalyseCommand->execute(Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Output\ConsoleOutput))
#2 phar:///usr/local/bin/phpstan/vendor/symfony/console/Application.php(831): _HumbugBox3fccee4f38a4\Symfony\Component\Console\Command\Command->run(Object(_HumbugBox3fccee4f38a4\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox3fccee4f38a4\Symfony\Co in phar:///usr/local/bin/phpstan/src/Command/CommandHelper.php on line 73

And removing the aforementioned line:

/var/www/magento $ phpstan analyse --autoload-file=app/bootstrap.php -c dev/tools/phpstan/config.neon --level=max app/code/
 203/203 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

/var/www/magento $ 

Proposed solution

Ideally, we wouldn't have this line at all in the code, but someone added it there for some reason. I couldn't find any context about it why it's there, it's not mentioned in the Release Notes for the 2.3.1 version, neither the commit that introduced it gives any context about it.

Can we either have it removed or have an explanation about why we can't?

Thanks!

Metadata

Metadata

Assignees

Labels

Fixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions