ZF-10691: Zend_Filter_StringTrim constructor does not set up options properly
Description
This is what is supplied in 1.11.0 Zend_Filter_StringTrim
/**
* Sets filter options
*
* @param string|array|Zend_Config $charList
* @return void
*/
public function __construct($charList = null) {
if ($charList instanceof Zend_Config) {
$charList = $charList->toArray();
} else if (!is_array($charList)) {
$options = func_get_args();
$temp['charlist'] = array_shift($options);
$options = $temp;
}
if (array_key_exists('charlist', $options)) {
$this->setCharList($options['charlist']);
}
}
if an array is given for the constructor parameter the local variable $options is never set and php gives a notice "Undefined variable: options on line 61". In addition, if the typical options array is given to the constructor, the options are never set for the filter. Furthermore if an instance of Zend_Config is supplied as the constructors parameter, it is converted to an array and then disregarded.
I am guessing the constructor was meant to be more like this Updated to reflect Ramon Henrique Ornelas comments and patch
/**
* Sets filter options
*
* @param string|array|Zend_Config $options
* @return void
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = func_get_args();
$temp['charlist'] = array_shift($options);
$options = $temp;
}
if (array_key_exists('charlist', $options)) {
$this->setCharList($options['charlist']);
}
}
Comments
Posted by Ramon Henrique Ornelas (ramon) on 2010-11-17T03:40:58.000+0000
{quote} $options['charlist'] = array_shift(func_get_args()); //?? I don't quite understand the purpose of this {quote}
This improvement only was done in php 5.3. See http://php.net/manual/en/… http://stackoverflow.com/questions/2309626/…
Greetings Ramon
Posted by Ramon Henrique Ornelas (ramon) on 2010-11-17T04:45:37.000+0000
Attach patch with tests.
Posted by quaintdesigns (quaintdesigns) on 2010-11-17T10:51:00.000+0000
Updated fix to reflect Ramon Henrique Ornelas comments and patch Altered phpDoc to reflect change of parameter name
Posted by Ramon Henrique Ornelas (ramon) on 2010-11-19T10:53:42.000+0000
Fixed in trunk r23396 merged to release branch 1.11 r23401 - thanks.