Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why generated not nullable fields have nullable types (?T) instead of type (T) #1409

Closed
SirMishaa opened this issue Dec 15, 2023 · 1 comment

Comments

@SirMishaa
Copy link

SirMishaa commented Dec 15, 2023

Hello,

I'm wondering something why when I generate a not-nullable field, like for example $name, the generated type is ?string and not string. This can have pretty huge impact when using tools like PHPStan since the usage of property may need additional check verification.

Is there something I miss ?
For context, I have read also this issue : #1074, but I don't see why it's still the case in 2023 in the latest version of the marker bundle.

class User {
    #[ORM\Column(length: 255)]
    private ?string $name= null;
}

Regards

@SirMishaa
Copy link
Author

SirMishaa commented Dec 15, 2023

Oh, my bad, I feel stupid.

I just thought about the case when you instantiate an entity, and you set some property using setter.

$user = new User();
$user->setName("uwu");

So that's why you need the field to be marked as nullable, since we're setting each field one by one, not in the instantiation of the class in the constructor for example.

If I'm correct, you can close this issue ! 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant