From 0121f23c7d3b419d41f7176ae0340a2bd7544645 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 1 Sep 2023 17:41:35 +0200 Subject: [PATCH] Add a note about constructor promotion and IDEs errors about attributes --- service_container/autowiring.rst | 8 ++++++++ service_container/tags.rst | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/service_container/autowiring.rst b/service_container/autowiring.rst index 85b649778bf..11a699e8a86 100644 --- a/service_container/autowiring.rst +++ b/service_container/autowiring.rst @@ -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. @@ -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 diff --git a/service_container/tags.rst b/service_container/tags.rst index 0bbe295cb7e..e077be252df 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -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. @@ -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