-
Notifications
You must be signed in to change notification settings - Fork 91
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
This extension represents an incorrect type mismatch for the simple_array type #436
Comments
What's your code and what error phpstan-doctrine reports? |
the code looks like this:
phpstan-doctrine report this:
The |
I get it, your suggestion makes sense, but I see Doctrine's behaviour as very surprising here. You can also get rid of this mess if you make the column non-nullable and represent empty arrays not in two ways (null and []), but only a single way ([]). |
@ondrejmirtes in the DB, an empty array is always represented as NULL, not as an empty string: https://github.com/doctrine/dbal/blob/3.6.1/src/Types/SimpleArrayType.php#L37-L44 So making the DB field non-nullable actually forbids storing an empty array. |
This leads to more constraints that should be reported here: Non-nullable column should only be combined with non-empty-array |
If we want to solve that, we would need 2 new methods actually, one describing the PHP type corresponding to a DB And then, |
This is a duplicate of #222 |
The
simple_array
type convertsNULL
database values to an empty array: https://github.com/doctrine/dbal/blob/3.6.1/src/Types/SimpleArrayType.php#L53-L57This means that a nullable column does not mean that the PHP property needs to be nullable.
This would probably require a way for type descriptors to tell whether they have a special handling of
null
or no.The text was updated successfully, but these errors were encountered: