diff --git a/src/Symfony/Component/VarExporter/Internal/Registry.php b/src/Symfony/Component/VarExporter/Internal/Registry.php index 629836b00bc0d..31ec4a0d790e1 100644 --- a/src/Symfony/Component/VarExporter/Internal/Registry.php +++ b/src/Symfony/Component/VarExporter/Internal/Registry.php @@ -65,14 +65,14 @@ public static function f($class) public static function getClassReflector($class, $instantiableWithoutConstructor = false, $cloneable = null) { - if (!\class_exists($class) && !\interface_exists($class, false) && !\trait_exists($class, false)) { + if (!($isClass = \class_exists($class)) && !\interface_exists($class, false) && !\trait_exists($class, false)) { throw new ClassNotFoundException($class); } $reflector = new \ReflectionClass($class); if ($instantiableWithoutConstructor) { $proto = $reflector->newInstanceWithoutConstructor(); - } elseif (!$reflector->isInstantiable()) { + } elseif (!$isClass || $reflector->isAbstract()) { throw new NotInstantiableTypeException($class); } elseif ($reflector->name !== $class) { $reflector = self::$reflectors[$name = $reflector->name] ?? self::getClassReflector($name, $instantiableWithoutConstructor, $cloneable); diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/private-constructor.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/private-constructor.php new file mode 100644 index 0000000000000..b29978b7ab91c --- /dev/null +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/private-constructor.php @@ -0,0 +1,17 @@ + [ + 'prop' => [ + 'bar', + ], + ], + ], + $o[0], + [] +); diff --git a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php index 5bb03d8ce1fc7..f2cd3ecd6de9d 100644 --- a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php +++ b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php @@ -197,6 +197,8 @@ public function provideExport() yield ['abstract-parent', new ConcreteClass()]; yield ['foo-serializable', new FooSerializable('bar')]; + + yield ['private-constructor', PrivateConstructor::create('bar')]; } } @@ -250,6 +252,21 @@ private function __clone() } } +class PrivateConstructor +{ + public $prop; + + public static function create($prop): self + { + return new self($prop); + } + + private function __construct($prop) + { + $this->prop = $prop; + } +} + class MyPrivateValue { protected $prot; 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