I was being exceptionally diligent today and decided to return-type hint all of my symfony entity methods. So:
<?php
Class User {
private string $username;
public method getUsername(): string {}
}
all good and well, until I made a form to create a new user:
$user = new User();
$this->createForm(SignupType::class, $user);
when the form is displayed, Symfony automatically gets the properties of this new instance of User $user
. But since it is a new instantiation, its username
property is of course still null
, which is an incorrect return type as it needs to be string
.
Should I either:
- have no return-type hinting in Symfony entities (meh);
- set
$username = ''
(but hat kind of defeats the purpose of not allowing blanks and I can see all sorts of errors evolving); or - unmap the field on the symfony form
- other possible solutions...