Skip to content

Wrong closure scope class reported for static methods #8932

Closed
@nicolas-grekas

Description

@nicolas-grekas

Description

The following code:

class A
{
    public static function b()
    {
        echo static::class;
    }
}

class B extends A
{
}

$c = ['B', 'b'];

$d = \Closure::fromCallable($c);

$r = new \ReflectionFunction($d);

var_dump($r->getClosureScopeClass());

$d();

Resulted in this output:

object(ReflectionClass)#41 (1) {
  ["name"]=>
  string(1) "A"
}
B

But I expected this output instead:

object(ReflectionClass)#41 (1) {
  ["name"]=>
  string(1) "B"
}
B

Right now, there is no way to turn back a named closure into a regular callable because reflection doesn't give back the "called class" ("B" here.)

See code running at https://3v4l.org/OpEA9

PHP Version

PHP >= 7.1

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions