ZF-3757: Bug in constructor method of the Zend_Validate_File_Size class

Description

When passing an array of min and max file sizes of the Zend_Validate_File_Size class, the max value is lost and a notice is raised. Below is the code I've tried :

$oFileTransfer = new Zend_File_Transfer_Adapter_Http(); $oFileTransfer ->addValidators('Size', array('min'=>'50kB','max'=>'5Mb'))->addValidators('Extension', 'png')->setDestination(dirname(FILE).'/uploads')->receive();

And below is the dump of my XDebug debug backtrace.

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /home/noeweb5/communs/library/Zend/Validate/File/Size.php on line 96 Call Stack

Time Memory Function Location

1 0.0011 68608 {main}( ) ../upload.php:0 2 0.0736 2749728 Zend_File_Transfer_Adapter_Abstract->addValidators( ) ../upload.php:32 3 0.0752 2818228 Zend_Validate_File_Size->__construct( ) ../Abstract.php:140 4 0.0752 2818716 array_key_exists ( ) ../Size.php:96

The bug comes from here in the __construct() method of Zend_Validate_File_Size :

[l.91] if (array_key_exists('min', $min)) { $min = $min['min']; // Here $min is not an array anymore but a string value so the 'max' index doesn't exist anymore if (array_key_exists('max', $min)) { $max = $min['max']; } }

The way to fix it is to use a temporary array like this :

if (array_key_exists('min', $min)) { $tmp = $min; $min = $min['min']; // Here $min is not an array anymore but a string value so the 'max' index doesn't exist anymore if (array_key_exists('max', $tmp)) { $max = $tmp['max']; } unset($tmp); }

Comments

I had the code I've tried.

Solved with r10418.

Btw: Your patch is ineffective. A simple statement switch does the same and is faster. ;-)