Zend Framework

Zend_Controller_Request_Abstract::setParams is not unsetting pre-existing values

Details

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())

Activity

Hide
Stefano Tamagnini added a comment -

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;
    }
Show
Stefano Tamagnini added a comment - 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;
    }
Hide
Ralph Schindler added a comment -

Matthew, any notes on this?

Show
Ralph Schindler added a comment - Matthew, any notes on this?
Hide
Pádraic Brady added a comment -

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

Show
Pádraic Brady added a comment - Fixed r24372. No apparent test breakages. Null check in method doesn't verify against original parameter so it missed the array addition issue.

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: