Skip to content

[DependencyInjection] Add a note about constructor promotion and IDEs errors about attributes #18813

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
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions service_container/autowiring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,13 @@ attribute like this::
}
}

.. note::

Some IDEs will show an error when using the ``#[Target]`` as in the previous example:
*"Attribute cannot be applied to a property because it does not contain the 'Attribute::TARGET_PROPERTY' flag"*.
The reason is that thanks to `PHP constructor promotion`_ this constructor
argument is both a parameter and a class property. You can safely ignore this error message.

.. versionadded:: 5.3

The ``#[Target]`` attribute was introduced in Symfony 5.3.
Expand Down Expand Up @@ -737,3 +744,4 @@ over all code.

.. _ROT13: https://en.wikipedia.org/wiki/ROT13
.. _service definition prototype: https://symfony.com/blog/new-in-symfony-3-3-psr-4-based-service-discovery
.. _`PHP constructor promotion`: https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion
10 changes: 10 additions & 0 deletions service_container/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,14 @@ directly via PHP attributes:
;
};

.. note::

Some IDEs will show an error when using the ``#[TaggedIterator]`` together
with the `PHP constructor promotion`_:
*"Attribute cannot be applied to a property because it does not contain the 'Attribute::TARGET_PROPERTY' flag"*.
The reason is that those constructor arguments are both parameters and class
properties. You can safely ignore this error message.

.. versionadded:: 5.3

The ``#[TaggedIterator]`` attribute was introduced in Symfony 5.3 and requires PHP 8.
Expand Down Expand Up @@ -1092,3 +1100,5 @@ be used directly on the class of the service you want to configure::
.. versionadded:: 5.3

The ``#[AsTaggedItem]`` attribute was introduced in Symfony 5.3.

.. _`PHP constructor promotion`: https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion