Skip to content

gen_stub: Conditionally include zend_attributes.h to arginfo based on usage#21570

Open
dkulyk wants to merge 2 commits intophp:masterfrom
dkulyk:gen_stub
Open

gen_stub: Conditionally include zend_attributes.h to arginfo based on usage#21570
dkulyk wants to merge 2 commits intophp:masterfrom
dkulyk:gen_stub

Conversation

@dkulyk
Copy link
Copy Markdown

@dkulyk dkulyk commented Mar 29, 2026

Conditionally include zend_attributes.h only when attributes are actually used.

Currently, zend_attributes.h must be explicitly included in C source files even when only common attributes (e.g. #[\Deprecated]) are needed. This introduces unnecessary coupling between extensions and attribute internals.

This change removes the requirement to manually include the header for common attributes, reducing boilerplate and avoiding unnecessary dependencies.

It does not affect behavior or runtime — only improves developer ergonomics and compilation dependencies.

Copy link
Copy Markdown
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

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

Yes, please. I don't necessarily agree with the implementation (it feels hack-ish), but the generated arginfo should absolutely be self-contained.

@dkulyk
Copy link
Copy Markdown
Author

dkulyk commented Mar 29, 2026

I had a few ideas:

  • pass context through all functions and collect dependency information
  • scan existing metadata for attribute usage
  • current implementation - only check function usage, since it is the simplest one

I would prefer the first option, since it also gives us room to add other features later.

What do you think?

@TimWolla
Copy link
Copy Markdown
Member

What do you think?

I don't have a strong opinion here, as I am not the maintainer of the gen_stub.php script and just make small fixes every now and then.

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.

2 participants