phpstan: FileReadTrapStreamWrapper::stream_eof is not implemented! since 0.12.84

Bug report

Since upgrading phpstan/phpstan (0.12.83 => 0.12.84), I encounter this error on CircleCI :

#!/bin/bash -eo pipefail php bin/phpstan analyse --no-interaction --no-progress Note: Using configuration file /home/circleci/project/symfony/phpstan.neon.dist. PHP Warning: include(): PHPStan\Reflection\BetterReflection\SourceLocator\FileReadTrapStreamWrapper::stream_eof is not implemented! Assuming EOF in phar:///home/circleci/project/symfony/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/ClassLoader.php on line 478 Warning: include(): PHPStan\Reflection\BetterReflection\SourceLocator\FileReadTrapStreamWrapper::stream_eof is not implemented! Assuming EOF in phar:///home/circleci/project/symfony/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/ClassLoader.php on line 478 zend_mm_heap corrupted

Exited with code exit status 1 CircleCI received exit code 1

Code snippet that reproduces the problem

Update phpstan to 0.12.84 and run php bin/phpstan analyse --no-interaction --no-progress with a custom config file :

includes:
    - vendor/phpstan/phpstan-symfony/extension.neon
    - vendor/phpstan/phpstan-symfony/rules.neon
parameters:
    parallel:
        maximumNumberOfProcesses: 1
    level: 0
    paths:
        - src
        - tests
    excludes_analyse:
        - tests/DataFixtures
    tipsOfTheDay: false
    symfony:
        container_xml_path: '%rootDir%/../../../var/cache/test/App_KernelTestDebugContainer.xml'
    ignoreErrors:
        -
            message: '#Unsafe usage of new static\(\)\.#'
            paths:
                - [...]
        -
            message: '#Service "[^"]+" is private\.#'
            paths:
                - [...]

Expected output

#!/bin/bash -eo pipefail php bin/phpstan analyse --no-interaction --no-progress Note: Using configuration file /home/circleci/project/symfony/phpstan.neon.dist.

[OK] No errors

CircleCI received exit code 0

Could this be related to https://github.com/phpstan/phpstan-src/pull/491 ? Ping @rrazor

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 35 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I tested that on several docker images like so:

docker run -it --rm -v $(pwd):/app -w /app imagename vendor/bin/phpstan-copy.phar analyze --memory-limit=5G

Here are my results: ❌ spryker/php:7.3 ✔️ php:7.3.27-alpineprooph/php:7.3-cli-opcache ✔️ prooph/php:7.4-cli-opcache


Looks like this is related to opcache, so I tried to create a few small images and test that again: ❌ alfredbez-local/php-7.2-alpine-opcache ✔️ php:7.2-alpinealfredbez-local/php-7.3-alpine-opcache ✔️ php:7.3-alpine ✔️ alfredbez-local/php-7.4-alpine-opcache ✔️ php:7.4-alpine

Here’s how I build the images to test that:

# 7.2-alpine-opcache/Dockerfile
FROM php:7.2-alpine
RUN docker-php-ext-configure opcache --enable-opcache && docker-php-ext-install opcache
COPY config/opcache.ini $PHP_INI_DIR/conf.d/
docker build -t alfredbez-local/php-7.2-alpine-opcache . # run this in the folder where the Dockerfile is
# 7.3-alpine-opcache/Dockerfile
FROM php:7.3-alpine
RUN docker-php-ext-configure opcache --enable-opcache && docker-php-ext-install opcache
COPY config/opcache.ini $PHP_INI_DIR/conf.d/
docker build -t alfredbez-local/php-7.3-alpine-opcache .
# 7.4-alpine-opcache/Dockerfile
FROM php:7.4-alpine
RUN docker-php-ext-configure opcache --enable-opcache && docker-php-ext-install opcache
COPY config/opcache.ini $PHP_INI_DIR/conf.d/
docker build -t alfredbez-local/php-7.4-alpine-opcache .

The output of the phar provided by @rrazor looks like this:

$ docker run -it --rm -v $(pwd):/app -w /app alfredbez-local/php-7.3-alpine-opcache:latest vendor/bin/phpstan-copy.phar analyze --memory-limit=5G
Note: Using configuration file /app/phpstan.neon.
  329/3280 [▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░]  10%zend_mm_heap corrupted

@ondrejmirtes Ah, sorry, to summarize:

  • There was a PHP warning emitted because stream_eof was not implemented; I implemented that and the warning went away
  • There is a zend_mm_heap corrupted panic in PHP versions 7.3 and earlier that surfaces when we attempt to allow require and require_once via the stream wrapper. Previously, the wrapper only supported autoloaders that used include or include_once.

The first issue was simple to resolve and the folks on this ticket have confirmed the PHP warnings went away with the .phar I published.

The second issue seems to be related to OpCache. The ways I’ve found that make the issue go away are either to disable OpCache for these PHP versions or to revert the previous work that supports require and require_once.

Sounds like you are OK with dropping OpCache for older PHP versions, which is great.

I’ll submit a PR that fixes the stream_eof warning and solves the zend_mm_heap corrupted issue shortly.

@rrazor thank you! Yes I can test with a custom cloned repo

@adrienfr I have not been able to reproduce this issue with the code provided on my own. If I provide a clone of the phpstan repo with a modified .phar would you be willing to test it out in your environment, please? I suspect it’s either related to loading very large files or it is an issue only seen on specific architectures.