Skip to content

Commit 37924b4

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 ce2673d commit 37924b4

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
@@ -32,7 +32,7 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
3232
{% if property.isInternal() %}private{% else %}protected{% endif %} ${{ property.getAttribute() }}{% if not viewHelper.isNull(property.getDefaultValue()) %} = {{ property.getDefaultValue() }}{% endif %};
3333
{% endforeach %}
3434
/** @var array */
35-
protected $_rawModelDataInput = [];
35+
protected $modelData = [];
3636

3737
{% if generatorConfiguration.collectErrors() %}
3838
/** @var {{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }} Collect all validation errors */
@@ -70,7 +70,7 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
7070
}
7171
{% endif %}
7272

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

7575
{{ schemaHookResolver.resolveConstructorAfterValidationHook() }}
7676
}
@@ -98,9 +98,9 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
9898
*
9999
* @return array
100100
*/
101-
public function getRawModelDataInput(): array
101+
public function getModelData(): array
102102
{
103-
return $this->_rawModelDataInput;
103+
return $this->modelData;
104104
}
105105

106106
{% foreach schema.getProperties() as property %}
@@ -154,7 +154,7 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
154154
{% endif %}
155155

156156
$this->{{ property.getAttribute() }} = $value;
157-
$this->_rawModelDataInput['{{ property.getName() }}'] = ${{ property.getAttribute() }};
157+
$this->modelData['{{ property.getName() }}'] = ${{ property.getAttribute() }};
158158

159159
{{ schemaHookResolver.resolveSetterAfterValidationHook(property) }}
160160

0 commit comments

Comments
 (0)