Skip to content

Fix ReflectionFunction::isDeprecated() for materialized __call() #17914

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

Merged

Conversation

TimWolla
Copy link
Member

Fixes #17913

call.handler = zend_closure_call_magic;
call.function_name = mptr->common.function_name;
call.scope = mptr->common.scope;
call.doc_comment = NULL;
call.attributes = mptr->common.attributes;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand, why I do not need to increase the refcount here: If I do, I get a leak.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call isn't a trampoline, and the function call is freed in zend_closure_free_storage. The attributes are ignored by zend_closure_free_storage. So you're counting on that the attributes of the original function outlive the closure instance.

Copy link
Member

@nielsdos nielsdos Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I actually wonder why we refcount the attributes for trampolines in the first place. They always come from a real function, and real functions should outlive trampolines I think. Maybe I'm missing something...
EDIT: I'm running the test suite now with refcounting removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to work fine.

@DanielEScherzer
Copy link
Member

The deprecated attribute is only since 8.4, but if the patch is going to expose all of the attributes from __call and __callStatic to closures, shouldn't this be targeting 8.3?

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine according to the discussion in #17880
As for the target branch: this is likely safe for 8.3

@TimWolla
Copy link
Member Author

As for the target branch: this is likely safe for 8.3

I can do this, but that would require cherry-picking f37b165 and 2542357 (incl. the tests that don't directly apply to 8.3, resulting in messy merges).

Therefore I'd rather not do this, because for isDeprecated() it's an actual bugfix (the warning behavior is inconsistent with Reflection), but for other attributes it's more of a feature request.

@nielsdos
Copy link
Member

@TimWolla I agree, let's keep this in 8.4.

@TimWolla TimWolla merged commit 2e999ba into php:PHP-8.4 Feb 27, 2025
10 checks passed
TimWolla added a commit that referenced this pull request Feb 27, 2025
* PHP-8.4:
  Fix `ReflectionFunction::isDeprecated()` for materialized `__call()` (#17914)
@TimWolla TimWolla deleted the reflectionfunction-is-deprecated-magic-call branch March 27, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants