Skip to content

Commit aa73335

Browse files
committed
minor #18813 [DependencyInjection] Add a note about constructor promotion and IDEs errors about attributes (javiereguiluz)
This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Add a note about constructor promotion and IDEs errors about attributes Fixes #18071. I propose to include the full error message shown by the IDE so it's easier to find this when googling about the error. Commits ------- 0121f23 Add a note about constructor promotion and IDEs errors about attributes
2 parents 2f34dd2 + 0121f23 commit aa73335

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

service_container/autowiring.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@ attribute like this::
582582
}
583583
}
584584

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

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

738745
.. _ROT13: https://en.wikipedia.org/wiki/ROT13
739746
.. _service definition prototype: https://symfony.com/blog/new-in-symfony-3-3-psr-4-based-service-discovery
747+
.. _`PHP constructor promotion`: https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion

service_container/tags.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,14 @@ directly via PHP attributes:
717717
;
718718
};
719719
720+
.. note::
721+
722+
Some IDEs will show an error when using the ``#[TaggedIterator]`` together
723+
with the `PHP constructor promotion`_:
724+
*"Attribute cannot be applied to a property because it does not contain the 'Attribute::TARGET_PROPERTY' flag"*.
725+
The reason is that those constructor arguments are both parameters and class
726+
properties. You can safely ignore this error message.
727+
720728
.. versionadded:: 5.3
721729

722730
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::
10921100
.. versionadded:: 5.3
10931101

10941102
The ``#[AsTaggedItem]`` attribute was introduced in Symfony 5.3.
1103+
1104+
.. _`PHP constructor promotion`: https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion

0 commit comments

Comments
 (0)