diff --git a/src/Tools/EntityGenerator.php b/src/Tools/EntityGenerator.php index 04be655188..3c72da123a 100644 --- a/src/Tools/EntityGenerator.php +++ b/src/Tools/EntityGenerator.php @@ -767,6 +767,9 @@ private function generateEmbeddableConstructor(ClassMetadataInfo $metadata): str if ($fieldMapping['type'] === 'datetime') { $param = $this->getType($fieldMapping['type']) . ' ' . $param; + if (! empty($fieldMapping['nullable'])) { + $param = '?' . $param; + } } if (! empty($fieldMapping['nullable'])) { @@ -1385,6 +1388,9 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, if ($typeHint && ! isset($types[$typeHint])) { $variableType = '\\' . ltrim($variableType, '\\'); $methodTypeHint = '\\' . $typeHint . ' '; + if ($defaultValue === 'null') { + $methodTypeHint = '?' . $methodTypeHint; + } } $replacements = [