diff --git a/src/Generator/PropertyGenerator.php b/src/Generator/PropertyGenerator.php index 9ca6503d..c4979d15 100644 --- a/src/Generator/PropertyGenerator.php +++ b/src/Generator/PropertyGenerator.php @@ -35,7 +35,7 @@ public static function fromReflection(PropertyReflection $reflectionProperty) $allDefaultProperties = $reflectionProperty->getDeclaringClass()->getDefaultProperties(); - $defaultValue = $allDefaultProperties[$reflectionProperty->getName()]; + $defaultValue = $allDefaultProperties[$reflectionProperty->getName()] ?? null; $property->setDefaultValue($defaultValue); if ($defaultValue === null) { $property->omitDefaultValue = true; diff --git a/test/Generator/PropertyGeneratorTest.php b/test/Generator/PropertyGeneratorTest.php index 3552dcab..069bde00 100644 --- a/test/Generator/PropertyGeneratorTest.php +++ b/test/Generator/PropertyGeneratorTest.php @@ -16,6 +16,8 @@ use Laminas\Code\Generator\PropertyValueGenerator; use Laminas\Code\Generator\ValueGenerator; use Laminas\Code\Reflection\ClassReflection; +use Laminas\Code\Reflection\PropertyReflection; +use LaminasTest\Code\Generator\TestAsset\ClassWithTypedProperty; use PHPUnit\Framework\TestCase; use ReflectionProperty; use stdClass; @@ -324,4 +326,14 @@ public function testFromReflectionOmitsDefaultValueIfItIsNull(): void $this->assertSame(' public static $fooStaticProperty;', $code); } + + public function testFromReflectionOmitsTypeHintInTypedProperty(): void + { + $reflectionProperty = new PropertyReflection(ClassWithTypedProperty::class, 'typedProperty'); + + $generator = PropertyGenerator::fromReflection($reflectionProperty); + $code = $generator->generate(); + + self::assertSame(' private $typedProperty;', $code); + } } diff --git a/test/Generator/TestAsset/ClassWithTypedProperty.php b/test/Generator/TestAsset/ClassWithTypedProperty.php new file mode 100644 index 00000000..816200a6 --- /dev/null +++ b/test/Generator/TestAsset/ClassWithTypedProperty.php @@ -0,0 +1,15 @@ +typedProperty = $typedProperty; + } +}