From 77ae5d62e5d3cc66a0d4c5cecb28b669caa0b58c Mon Sep 17 00:00:00 2001 From: Alden Weddleton Date: Thu, 12 Mar 2026 12:08:01 -0400 Subject: [PATCH] fix: disable autoloading in typeIsValid to prevent fatal errors during generation class_exists() in typeIsValid() triggers the autoloader, which can cause fatal errors during code generation when a freshly-generated class extends a parent class that hasn't been generated yet. The generation order of structs is non-deterministic, so this produces intermittent failures. Passing false as the second argument to class_exists() disables autoloading. The subsequent stringIsValid() check still validates the type string format, so there is no loss of validation coverage. --- src/Element/TypeHintedElementTrait.php | 2 +- tests/Element/PhpFunctionParameterTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Element/TypeHintedElementTrait.php b/src/Element/TypeHintedElementTrait.php index b737c4c..9db14da 100644 --- a/src/Element/TypeHintedElementTrait.php +++ b/src/Element/TypeHintedElementTrait.php @@ -34,7 +34,7 @@ public static function typeIsValid($type): bool return is_null($type) || $type instanceof PhpClass - || (is_string($type) && class_exists($type)) + || (is_string($type) && class_exists($type, false)) || in_array($type, TypeHintedElementInterface::TYPES, true) || static::stringIsValid($type, true, true); } diff --git a/tests/Element/PhpFunctionParameterTest.php b/tests/Element/PhpFunctionParameterTest.php index ab0c21a..77114e3 100755 --- a/tests/Element/PhpFunctionParameterTest.php +++ b/tests/Element/PhpFunctionParameterTest.php @@ -46,6 +46,11 @@ public function testTypeIsValidAccentuated() $this->assertTrue(PhpFunctionParameter::typeIsValid('Partagé')); } + public function testTypeIsValidWithUnloadedFullyQualifiedClassName() + { + $this->assertTrue(PhpFunctionParameter::typeIsValid('\\Some\\Namespace\\NonExistentClass')); + } + public function testFloatValueForDeclaration() { $initialSerializePrecision = ini_get('serialize_precision');