Skip to content

Commit f0e65a8

Browse files
committed
Use $rawModelDataInput as construct function parameter name in Model.phptpl because when Symfony deserializer the object will not find the parameter value in the saved data and use the default parameter value(empty array).
Then the model construct function will get error: `Typed property must not be accessed before initialization` since PHP 7.4 see: https://github.com/symfony/symfony/blob/44db49fb8f6d70c4341120a3f8f1b1a1a0dfa014/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php#L380 and https://github.com/symfony/symfony/blob/44db49fb8f6d70c4341120a3f8f1b1a1a0dfa014/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php#L355
1 parent 2871e7a commit f0e65a8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Templates/Model.phptpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
4242
/**
4343
* {{ class }} constructor.
4444
*
45-
* @param array $modelData
45+
* @param array $rawModelDataInput
4646
*
4747
* @throws {% if generatorConfiguration.collectErrors() %}{{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }}{% else %}ValidationException{% endif %}
4848
*/
49-
public function __construct(array $modelData = [])
49+
public function __construct(array $rawModelDataInput = [])
5050
{
5151
{% if generatorConfiguration.collectErrors() %}
5252
$this->_errorRegistry = new {{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }}();
@@ -55,12 +55,12 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
5555
{{ schemaHookResolver.resolveConstructorBeforeValidationHook() }}
5656

5757
{% if schema.getBaseValidators() %}
58-
$this->executeBaseValidators($modelData);
58+
$this->executeBaseValidators($rawModelDataInput);
5959
{% endif %}
6060

6161
{% foreach schema.getProperties() as property %}
6262
{% if not property.isInternal() %}
63-
$this->process{{ viewHelper.ucfirst(property.getAttribute()) }}($modelData);
63+
$this->process{{ viewHelper.ucfirst(property.getAttribute()) }}($rawModelDataInput);
6464
{% endif %}
6565
{% endforeach %}
6666

@@ -70,7 +70,7 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
7070
}
7171
{% endif %}
7272

73-
$this->_rawModelDataInput = $modelData;
73+
$this->_rawModelDataInput = $rawModelDataInput;
7474

7575
{{ schemaHookResolver.resolveConstructorAfterValidationHook() }}
7676
}

0 commit comments

Comments
 (0)