Closed
Description
Symfony version(s) affected: 5.3.4 (and potentially other versions allowed to run in PHP 8.1)
Description
PHP 8.1 introduces the ability to add New in initializers. This breaks the ReflectionClassResource.php when the reflected object has the new syntax in the constructor.
How to reproduce
Run the following snippet on project root:
<?php
declare(strict_types=1);
use Symfony\Component\Config\Resource\ReflectionClassResource;
require_once __DIR__ . '/vendor/autoload.php';
final class DefaultObject
{
}
final class Testing
{
public function __construct(
private DefaultObject $test = new DefaultObject(),
) {
}
}
$reflectedClass = new ReflectionClass(Testing::class);
$reflectedClassResource = new ReflectionClassResource($reflectedClass);
$reflectedClassResource->isFresh((new DateTimeImmutable())->getTimestamp());
Possible Solution
I'm not very familiar with the mechanism of the symfony/config
package, but I'd be happy to help along the way or update this section upon looking in more detail in the code.
Additional context
Fatal error: Uncaught Error: Object of class DefaultObject could not be converted to string in /opt/project/vendor/symfony/config/Resource/ReflectionClassResource.php on line 205
Error: Object of class DefaultObject could not be converted to string in /opt/project/vendor/symfony/config/Resource/ReflectionClassResource.php on line 205
Call Stack:
0.0068 349976 1. {main}() /opt/project/agustin/bin/customConsole:0
0.1409 790096 2. Symfony\Component\Config\Resource\ReflectionClassResource->isFresh($timestamp = 1633013398) /opt/project/agustin/bin/customConsole:23
0.1409 790096 3. Symfony\Component\Config\Resource\ReflectionClassResource->computeHash() /opt/project/vendor/symfony/config/Resource/ReflectionClassResource.php:44
0.1410 796488 4. Symfony\Component\Config\Resource\ReflectionClassResource->generateSignature($class = class ReflectionClass { public string $name = 'Testing' }) /opt/project/vendor/symfony/config/Resource/ReflectionClassResource.php:115
3.8866 798088 5. preg_replace($pattern = '/^ @@.*/m', $replacement = '', $subject = class ReflectionMethod { public string $name = '__construct'; public string $class = 'Testing' }) /opt/project/vendor/symfony/config/Resource/ReflectionClassResource.php:205
3.8866 798192 6. ReflectionMethod->__toString() /opt/project/vendor/symfony/config/Resource/ReflectionClassResource.php:205