Skip to content

Commit 6bd1380

Browse files
committed
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.
1 parent 47fcae1 commit 6bd1380

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/Element/TypeHintedElementTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function typeIsValid($type): bool
3434
return
3535
is_null($type)
3636
|| $type instanceof PhpClass
37-
|| (is_string($type) && class_exists($type))
37+
|| (is_string($type) && class_exists($type, false))
3838
|| in_array($type, TypeHintedElementInterface::TYPES, true)
3939
|| static::stringIsValid($type, true, true);
4040
}

tests/Element/PhpFunctionParameterTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function testTypeIsValidAccentuated()
4646
$this->assertTrue(PhpFunctionParameter::typeIsValid('Partagé'));
4747
}
4848

49+
public function testTypeIsValidWithUnloadedFullyQualifiedClassName()
50+
{
51+
$this->assertTrue(PhpFunctionParameter::typeIsValid('\\Some\\Namespace\\NonExistentClass'));
52+
}
53+
4954
public function testFloatValueForDeclaration()
5055
{
5156
$initialSerializePrecision = ini_get('serialize_precision');

0 commit comments

Comments
 (0)