Skip to content
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

Docs: add a page about zend_attribute #18122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DanielEScherzer
Copy link
Member

Work towards #15954

@DanielEScherzer DanielEScherzer added the Category: Documentation This is for documentation inside php-src, not on php.net label Mar 25, 2025
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this.

IMO, it would be useful to describe that zend_attribute is a compile-time concept. I.e. it refers to the lexical, static attribute in your source code, rather than an instance returned from reflection.

I also wonder whether it's necessary to describe each field. They are pretty self-explanatory with the exception of some, like offset.

Specifically, such explanations are not useful.

Where the name field stores the name used, and the zval value field stores the value.

Instead, it's likely possible to auto-link all references of zval in source code to the zval page.

And are *not* the same as the flags in ``Attribute::$flags``.

**********
metadata
Copy link
Member

Choose a reason for hiding this comment

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

The metadata and filename titles look wrong.

The ``lineno`` field holds the line number that the attribute is used on, for use in error messages.

The ``offset`` field is only used for attributes on parameters, and indicates *which* parameter the
attribute is applied to (since the attributes for a function's parameters are all stored together).
Copy link
Member

Choose a reason for hiding this comment

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

Maybe mention that function attributes have offset 0, while args have offset 1+.


The number of arguments that are passed to the attribute is stored in the ``argc`` field. But, since
attributes support the use of named parameters, storing just the parameters that were used is not
enough, the parameter names need to be stored too.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe mention that value may contain constant expressions that are evaluated when creating an instance of the attribute. Meaning if you have #[MyAttr(new Foo)], new Foo will be performed for every $reflectionAttr->newInstance().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Documentation This is for documentation inside php-src, not on php.net
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants