ZF-5163: _getParam in Controller/Action don't handle 0


Example $this->_setParam('foo', 0); $foo = $this->_getParam('foo', -1);

$foo is set to -1 instead of the expected value 0

This is because the method in Controller/Action.php does a null == $value check instead of null === $value. It should be modified to look like this: protected function _getParam($paramName, $default = null) { $value = $this->getRequest()->getParam($paramName); if ((null === $value) && (null !== $default)) { $value = $default; }

return $value;



Set component and auto reassign

This issue still affects version 1.7.8 !!

The bug also occurs if param's value is false.

By any means, this is not minor!

The params come from the url, so technically they will always be strings, the number 0 and a boolean value aren't really possible to be part of the params.

but I agree that for sanity's sake it should be fixed.

In my case i was setting values in one action using _setParam and then used _getParam in another action, so it does not always have to come from the URL.

This is a MAJOR issue !

As proposed the simple patch if ((null == $value) && (null !== $default)) {


if ((null === $value) && (null !== $default)) {

Fixes it. Problem with 0 and "", both handled like param not present.

Please fix it ASAP.

Attached (simple) patch implementing the suggested solution, if this is deemed a bug by upstream. I would suggest it is.

~My CLA has been submitted, -but not yet processed-~

Attached a unit test that tests the conditions of this bug. Is it a good idea to add these conditions (0 as value for setParam) to other unit tests like getParams as well?

Resolved in r19763