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

Prevent passing null values as a request parameter

Open nikophil opened this issue 2 years ago • 2 comments

Hello,

with ORM, this code leads to invalid SQL queries when $field is null:

->andWhere('t.field = :field')
->setParameter('field',  $field)

see https://github.com/doctrine/orm/issues/7289

do you think it could be nice to have a rule that checks no nullable param is passed to setParameter() / setParameters()?

I'm wondering if it would not lead to some false negatives cases where it is valid to pass null as parameter... :thinking:

nikophil avatar Jan 11 '23 17:01 nikophil

This would be a nice addition 👍

gndk avatar Mar 15 '23 18:03 gndk

If null is not supported/makes no sens to setParameter, it should be on the function signature instead https://github.com/doctrine/orm/blob/5a40b99e11a0de532eb866f062dccad20da19add/src/QueryBuilder.php#L436

Changing mixed to bool|int|float|string|array|object

VincentLanglet avatar Feb 09 '24 08:02 VincentLanglet