phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

Decimal col type throws Property type mapping mismatch:

Open aszenz opened this issue 5 years ago • 3 comments

I have a decimal column in one of the entities, annotating its type with float throws this:

database can contain string but property expects float.

I'm not sure what the issue is here, keeping the type="float" in @ORM\Column doesn't help the same error is throw, what type should i annotate my column with.

Annotating it with float|int|string works but I'm not sure its correct

aszenz avatar Sep 28 '20 06:09 aszenz

I'm not sure how this works in PDO, the DecimalType simply returns the value returned by the database driver: https://github.com/doctrine/dbal/blob/37f252326bdc4f83754e114fb64aa0763e73fa48/src/Types/DecimalType.php#L28-L34

So I guess it can really be float|int|string depending on some outside factors.

ondrejmirtes avatar Sep 28 '20 09:09 ondrejmirtes

Is a numeric-string a better type for Decimal columns?

aszenz avatar Dec 02 '20 06:12 aszenz