Skip to content

Reflecting a class with an eval()-declared parent emits a file_get_contents() warning #244

Closed
goaop/framework
#784

Description

@lisachenko

Problem

When a parsed class inherits methods from an already declared parent, ReflectionClassLikeTrait::wrapInheritedMethod() tries to convert the native inherited methods into parsed ones with ReflectionEngine::parseClass(). ReflectionEngine::locateClassFile() takes the file of a declared class from native reflection. For a class declared by eval() that is a pseudo name such as /path/to/file.php(12) : eval()'d code, and parseFile() then calls file_get_contents() on it:

PHP Warning: file_get_contents(/path/to/probe.php(3) : eval()'d code): Failed to open stream: No such file or directory
in src/ReflectionEngine.php:277

parseFile() throws a ReflectionException right after, which wrapInheritedMethod() catches, so the native method is used as intended. But the warning escapes. Tools that turn warnings into errors fail on it: the Go! AOP cache warm-up reports the file as not woven (found while working on goaop/goaop-symfony-bundle#17).

Reproduction on 4.x:

eval('namespace EvalProbe; class EvalParent { public function inherited(): int { return 1; } }');
// Child.php: namespace EvalProbe; class Child extends EvalParent { public function own(): void {} }
$file  = new Go\ParserReflection\ReflectionFile(__DIR__ . '/Child.php');
$class = $file->getFileNamespace('EvalProbe')->getClass('EvalProbe\Child');
$class->getMethods(); // warning from file_get_contents()

Proposed fix

In locateClassFile(), when a declared class reports a file name that is not a real file, throw the InvalidArgumentException that callers already treat as "not found", without reading the file. The callers then fall back to native reflection silently. Fix on 4.x; it flows into master through the cascade merge.

Activity

  1. lisachenko commented on Nov 2, 2026

    @lisachenko
    MemberAuthor

    Fixed by #246, merged into 4.x and carried into master by the cascade PR #249. GitHub didn't close this automatically because #246 targeted 4.x, not the default branch.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions