diff --git a/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php b/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php index 88fa9e3506f33..a3d4d9dda9f57 100644 --- a/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php +++ b/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php @@ -39,7 +39,7 @@ public function __construct(string $serviceId, string|\Closure $message = '', in parent::__construct('', $code, $previous); $this->message = new class($this->message, $this->messageCallback) { - private string $message; + private string|self $message; private ?\Closure $messageCallback; public function __construct(&$message, &$messageCallback) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Exception/AutowiringFailedExceptionTest.php b/src/Symfony/Component/DependencyInjection/Tests/Exception/AutowiringFailedExceptionTest.php index 996b891016956..f94f9a4eb8c16 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Exception/AutowiringFailedExceptionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Exception/AutowiringFailedExceptionTest.php @@ -25,4 +25,25 @@ public function testGetMessageCallbackWhenMessageIsNotANotClosure() self::assertNull($exception->getMessageCallback()); } + + public function testLazyness() + { + $counter = 0; + $exception = new AutowiringFailedException( + 'App\DummyService', + function () use (&$counter) { + ++$counter; + + throw new \Exception('boo'); + } + ); + + $this->assertSame(0, $counter); + + $this->assertSame('boo', $exception->getMessage()); + $this->assertSame(1, $counter); + + $this->assertSame('boo', $exception->getMessage()); + $this->assertSame(1, $counter); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy