zendframework / zend-db

Db component from Zend Framework
BSD 3-Clause "New" or "Revised" License
101 stars 122 forks source link

Incorrect Sql Expression parameters when passing zero in the constructor #381

Open albertor24 opened 5 years ago

albertor24 commented 5 years ago

I am trying to create an expression that has zero as the parameter value. However, the parameters incorrectly show as empty.

Code to reproduce the issue

$expr = new \Zend\Db\Sql\Expression('?', '0');
print_r($expr->getParameters());

Expected results

It prints "0"

Actual results

It prints empty array

Proposed fix

https://github.com/zendframework/zend-db/blob/master/src/Sql/Expression.php#L59

In Zend\Db\Sql\Expression, update the constructor to explicitly check for '0' when setting parameters

if ($parameters || $parameters === '0') {
     $this->setParameters($parameters);
}
michalbundyra commented 5 years ago

@albertor24 Please submit PR and add test to cover your case 👍

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at https://github.com/laminas/laminas-db/issues/6.