Skip to content

Commit 281d758

Browse files
committed
[#13619] Moved text into a note and added versionadded
1 parent 211ea43 commit 281d758

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

service_container/calls.rst

+24-12
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,30 @@ The configuration to tell the container it should do so would be like:
144144
$container->register(MessageGenerator::class)
145145
->addMethodCall('withLogger', [new Reference('logger')], true);
146146
147-
If autowire is enabled, you can also use annotations; with the previous exemple it would be::
147+
.. tip::
148148

149-
/**
150-
* @required
151-
* @return static
152-
*/
153-
public function withLogger(LoggerInterface $logger)
154-
{
155-
$new = clone $this;
156-
$new->logger = $logger;
149+
If autowire is enabled, you can also use annotations; with the previous
150+
example it would be::
157151

158-
return $new;
159-
}
152+
/**
153+
* @required
154+
* @return static
155+
*/
156+
public function withLogger(LoggerInterface $logger)
157+
{
158+
$new = clone $this;
159+
$new->logger = $logger;
160+
161+
return $new;
162+
}
163+
164+
You can also leverage the PHP 8 ``static`` return type instead of the
165+
``@return static`` annotation. If you don't want a method with a
166+
PHP 8 ``static`` return type and a ``@required`` annotation to behave as
167+
a wither, you can add a ``@return $this`` annotation to disable the
168+
*returns clone* feature.
169+
170+
.. versionadded:: 5.1
160171

161-
You can also leverage the PHP8 ``static`` return type instead of the ``@return static`` annotation. Note if you don't want a method with a PHP8 ``static`` return type and a ``@required`` annotation to behave as a wither, you can add a ``@return $this`` annotation to disable the *returns clone* feature.
172+
Support for the PHP 8 ``static`` return type was introduced in
173+
Symfony 5.1.

0 commit comments

Comments
 (0)