ZF-3472: Zend_Controller_Request_Abstract::setParams is not unsetting pre-existing values

Description


require_once 'Zend/Controller/Request/Simple.php';
$r = new Zend_Controller_Request_Simple();
$r->setParam('key', 'value');
$r->setParams(
    array(
        'key' => null
    )
);
var_dump($r->getParams());

The preceding code should output:


array(0) {
}

but is actually outputting:


array(1) {
  ["key"]=>
  string(5) "value"
}

{{getParams()}} should be returning an empty array because {{setParams}} is defining {{key}} to be {{null}} and should therefore be calling {{unset}} on that value.

If I modified the code to the following, then everything works as expected.


<?php
require_once 'Zend/Controller/Request/Simple.php';
$r = new Zend_Controller_Request_Simple();
$r->setParam('key', 'value');
$r->setParam('key', null);
var_dump($r->getParams())

Comments

REFERENCE ZF 1.10.1 try:


$request->setParam('variable',null);
unset($_GET['variable']);
unset($_POST['variable']);

correct unset variable into Zend_Controller_Request_Http, because into Zend_Controller_Request_Http on getParam(...) it try to find variable name into $_GET & $_POST :


    public function getParam($key, $default = null)
    {
        $keyName = (null !== ($alias = $this->getAlias($key))) ? $alias : $key;

        $paramSources = $this->getParamSources();
        if (isset($this->_params[$keyName])) {
            return $this->_params[$keyName];
        } elseif (in_array('_GET', $paramSources) && (isset($_GET[$keyName]))) {
            return $_GET[$keyName];
        } elseif (in_array('_POST', $paramSources) && (isset($_POST[$keyName]))) {
            return $_POST[$keyName];
        }

        return $default;
    }

Matthew, any notes on this?

Fixed r24372. No apparent test breakages. Null check in method doesn't verify against original parameter so it missed the array addition issue.