Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TimWolla opened this issue Feb 24, 2025 · 0 comments

Comments

@TimWolla
Copy link
Member

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

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

No branches or pull requests

2 participants