Skip to content

fix(engine): report a class declared by eval() as not found instead of reading its pseudo file - #246

Merged
lisachenko merged 2 commits into
4.xfrom
fix/eval-declared-parent-warning
Nov 2, 2026
Merged

lisachenko merged 2 commits into
4.xfrom
fix/eval-declared-parent-warning

Conversation

@lisachenko

Copy link
Copy Markdown
Member

Summary

Fixes #244. ReflectionEngine::locateClassFile() now throws the InvalidArgumentException that callers already treat as "not found" when an already declared class reports a file name that isn't a real file (file.php(12) : eval()'d code). Before, parseFile() ran file_get_contents() on that pseudo name and emitted a warning before failing. Reflecting a class that inherits methods from an eval()-declared parent still falls back to the native methods, now without the warning.

Targets 4.x; cascade-merge.yml carries it into master after the merge.

Changes

  • src/ReflectionEngine.php: is_file() check on the file name from native reflection. Only the branch for already declared classes is affected; the locator branch is unchanged.
  • tests/EvalDeclaredParentTest.php with the stub tests/Stub/FileWithEvalDeclaredParent.php (not part of getFilesToAnalyze(), it extends a class that only exists after the eval()):
    • locateClassFile() reports an eval()-declared class as not found;
    • getMethods() on a child of an eval()-declared parent emits no warning and still returns the inherited method.

Testing

  • Both new tests fail on 4.x without the change and pass with it.
  • vendor/bin/phpunit: OK (13749 tests; the 133 skipped and 2 incomplete are already on 4.x).
  • vendor/bin/phpstan analyse src: 1 error, which 4.x already has without this change: Traits/ReflectionClassLikeTrait.php:1303, "Strict comparison using === between (int|string) and null will always evaluate to false".

Generated by Claude Code

…f reading its pseudo file

ReflectionEngine::locateClassFile() takes the file of an already declared class
from native reflection. For a class declared by eval() that is a pseudo name
("file.php(12) : eval()'d code"), and parseFile() raised a file_get_contents()
warning before failing. Reflecting a class that inherits methods from such a
parent emitted the warning, which tools that treat warnings as errors (the
Go! AOP cache warm-up) report as a failure. The class is now reported as not
found, so the callers fall back to native reflection without a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxhC1DaSZY1jAz2XfyjhPa

Copy link
Copy Markdown
Member Author

PHPStan analysis - PHP8.4 fails here, but not because of this PR. The only error is Traits/ReflectionClassLikeTrait.php:1303 ("Strict comparison using === between (int|string) and null will always evaluate to false"), in code this PR doesn't touch, and 4.x itself is red with it (the last PHPStan run on its head, 1f096af). PHPStan 2.3 now detects a redundant null check there. The fix is in #247, against 4.x; once it is merged, this PR is green after merging 4.x in.


Generated by Claude Code

@lisachenko
lisachenko marked this pull request as ready for review November 2, 2026 17:25
@lisachenko
lisachenko merged commit 77e7862 into 4.x Nov 2, 2026
7 checks passed
@lisachenko
lisachenko deleted the fix/eval-declared-parent-warning branch November 2, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants