Skip to content

ReflectionFunction::isDeprecated() returns incorrect results for closures created from magic __call() #17913

Closed
@TimWolla

Description

@TimWolla

Description

The following code:

<?php

class Foo {
    #[Deprecated("xyzzy")]
    public function __call(string $name, array $args) {
    }
}

$foo = new Foo;
$closure = Closure::fromCallable([$foo, 'test']);
$closure2 = $foo->test(...);

$rc = new ReflectionFunction($closure);
var_dump($rc->getAttributes());
var_dump($rc->isDeprecated());

$rc = new ReflectionFunction($closure2);
var_dump($rc->getAttributes());
var_dump($rc->isDeprecated());

$closure();
$closure2();

Resulted in this output:

array(0) {
}
bool(false)
array(0) {
}
bool(false)

Deprecated: Method Foo::__call() is deprecated, xyzzy in /in/PZ4f2 on line 21

Deprecated: Method Foo::__call() is deprecated, xyzzy in /in/PZ4f2 on line 22

But I expected this output instead:

array(1) {
  [0]=>
  object(ReflectionAttribute)#5 (1) {
    ["name"]=>
    string(10) "Deprecated"
  }
}
bool(true)
array(1) {
  [0]=>
  object(ReflectionAttribute)#4 (1) {
    ["name"]=>
    string(10) "Deprecated"
  }
}
bool(true)

Deprecated: Method Foo::__call() is deprecated, xyzzy in /in/PZ4f2 on line 21

Deprecated: Method Foo::__call() is deprecated, xyzzy in /in/PZ4f2 on line 22

Related to #17597 and related to #17880.

PHP Version

PHP 8.4.4

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