Reproduce autoloader bug#4003
Draft
staabm wants to merge 2 commits into
Draft
Conversation
staabm
commented
May 21, 2025
|
|
||
| spl_autoload_register(function($class) { | ||
| if ($class === \other12972\MyClass::class) { | ||
| throw new LogicException('this should not happen'); |
Contributor
Author
There was a problem hiding this comment.
in our real world project this autoloader is scanning some paths in the filesystem (similar to how a include-path worked in the past / or how the %PATH% variable works in a shell).
since it scans the filesystem it finds some files and includes them. this in turn leads to the problem described in phpstan/phpstan#12972 -> so invoking the autoloader leads side-effects, as files get included, which has impact on ReflectionClass->getFileName() invoked later on in PHPStan
| # host and only the build and test commands run inside a long-lived | ||
| # Alpine container via docker exec — native arm64, no QEMU. The steps | ||
| # mirror the musl leg of turbo-compile one for one. | ||
| runs-on: "ubuntu-24.04-arm" |
|
|
||
| - name: "Install bashunit" | ||
| run: "curl -s https://bashunit.typeddevs.com/install.sh | bash -s e2e/ 0.37.0" | ||
| uses: "TypedDevs/bashunit@ffa9c79e71ecbb9990e777348bc9ba12314b62d0" # 0.39.1 |
|
|
||
| - name: "Install bashunit" | ||
| run: "curl -s https://bashunit.typeddevs.com/install.sh | bash -s e2e/ 0.37.0" | ||
| uses: "TypedDevs/bashunit@ffa9c79e71ecbb9990e777348bc9ba12314b62d0" # 0.39.1 |
| fetch-depth: 0 # git log over turbo-ext/src needs full history | ||
|
|
||
| - name: "Install PHP" | ||
| uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # v2.37.2 |
| fetch-depth: 0 # the VERSION.txt written below bakes from git log over turbo-ext/src | ||
|
|
||
| - name: "Install PHP" | ||
| uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # v2.37.2 |
| fetch-depth: 0 | ||
|
|
||
| - name: "Install PHP" | ||
| uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # v2.37.2 |
| git -C /c/php-sdk checkout -q "$PHP_SDK_COMMIT" | ||
|
|
||
| - name: "Set up MSVC environment" | ||
| uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 |
| WANT_ZTS=$([ "${{ matrix.ts }}" = "zts" ] && echo 1 || echo 0) | ||
| [ "$(php -r 'echo (int) ((bool) PHP_ZTS);')" = "$WANT_ZTS" ] | ||
|
|
||
| - uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0 |
| persist-credentials: false | ||
|
|
||
| - name: "Install PHP" | ||
| uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # v2.37.2 |
| fi | ||
| php -m | grep phpstan_turbo | ||
|
|
||
| - uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
this test demonstrates how PHPStan analyzes code differently than it would happen at runtime.
runtime: run
php real-world.phpyou see the program runs, without the custom autoloader of
e2e/bug-12972b/autoloader.phpbeeing invoked.all involved classes are autoloaded by the composer class loader. the custom class loader is not invoked for
\other12972\MyClass::class.static analysis time: run
../../bin/phpstan analyzeyou see PHPStan invokes the custom class loader for class
\other12972\MyClass::class, which does not happen at regular runtime. the composer class loader is not invoked for\other12972\MyClass::class(like it is at runtime).because of the difference in autoloading functions order in runtime vs. analysis time we see errors which cannot happen at runtime - see phpstan/phpstan#12972