[php-src] Issue #8421: Attributes that target functions are not valid for anonymous functions defined within a method
| From: | ollieread | Date: | Thu, 21 Apr 2022 19:08:20 +0000 |
| Subject: | [php-src] Issue #8421: Attributes that target functions are not valid for anonymous functions defined within a method | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241138@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8421
Comment Author: ollieread
I don't actually know C, and the last 2 hours I spent going through the PHP source is quite
possibly the first time I've ever had to navigate a C codebase, but I think I have found the
issue. ([journey thread, if it helps](https://twitter.com/ollieread/status/1517196962935803906))
It's
ReflectionFunctionAbstract::getAttributes
(https://github.com/php/php-src/blob/master/ext/reflection/php_reflection.c#L1875)
```c
ZEND_METHOD(ReflectionFunctionAbstract, getAttributes)
{
reflection_object *intern;
zend_function *fptr;
uint32_t target;
GET_REFLECTION_OBJECT_PTR(fptr);
if (fptr->common.scope) {
target = ZEND_ATTRIBUTE_TARGET_METHOD;
} else {
target = ZEND_ATTRIBUTE_TARGET_FUNCTION;
}
reflect_attributes(INTERNAL_FUNCTION_PARAM_PASSTHRU,
fptr->common.attributes, 0, fptr->common.scope, target,
fptr->type == ZEND_USER_FUNCTION ? fptr->op_array.filename : NULL);
}
```
If the function reference has a scope, it assumes it's a method. I can't find anything
that would point to an easy fix, as it seems that within these chunks of code there's nothing
to identify a closure over any other kind of function. Not in reflection_type_t or
zend_function.type. There is zend_function.common.type which according to
a comment is never used.
Again, my C knowledge is limited (to the last 2 hours), but thought this may be able to help
someone.