Issues

ZF-10738: Zend_Validate_File_Upload not E_NOTICE compliant

Description

Zend_Validate_File_Upload may throw E_Notice warnings during validation.

public function isValid($value, $file = null)
{
    $this->_messages = null;
    if (array_key_exists($value, $this->_files)) {
        $files[$value] = $this->_files[$value];
    } else {
        foreach ($this->_files as $file => $content) {
            if (isset($content['name']) && ($content['name'] === $value)) {
                $files[$file] = $this->_files[$file];
            }

            if (isset($content['tmp_name']) && ($content['tmp_name'] === $value)) {
                $files[$file] = $this->_files[$file];
            }
        }
    }

Should be

public function isValid($value, $file = null)
{
    $this->_messages = null;

if (is_array($this->_files) && array_key_exists($value, $this->_files)) { $files[$value] = $this->_files[$value]; } else { foreach ($this->_files as $file => $content) { if (isset($content['name']) && ($content['name'] === $value)) { $files[$file] = $this->_files[$file]; }

            if (isset($content['tmp_name']) && ($content['tmp_name'] === $value)) {
                $files[$file] = $this->_files[$file];
            }
        }
    }

Comments

Dittos for public function setFiles($files = array()). The foreach loop assumes that $this->_files will be an array when, for some stupid reason, on my machine it is not.

I've added a test to Zend_Validate_File_UploadTest which reproduces your issue. Patch is attached.

I have attached a combined test+fix path for this issue.

Thanks for the patch and test Adam. Applied modified patch to trunk r23569 and merged to release branch 1.11 in r23570. It is cleaner to ensure that setFiles() always leaves the internal _files property as an array instead of adding the is_array tests in various places.

Why this issue is reopened?

Fixed in ZF2 with GH-264