ZF-9261: Error setting options to Zend_File_Transfer_Adapter_Abstract

Description

Hi there,

There is a little bug in the code of setOptions function.


    public function setOptions($options = array(), $files = null) {
        $file = $this->_getFiles($files, false, true);

        if (is_array($options)) {
            if ($file === null) {
                $this->_options = array_merge($this->_options, $options);
            }

            foreach ($options as $name => $value) {
                foreach ($file as $key => $content) {
                    switch ($name) {
                        case 'magicFile' :
                            $this->_files[$key]['options'][$name] = (string) $value;
                            break;

                        case 'ignoreNoFile' :
                        case 'useByteString' :
                            $this->_files[$key]['options'][$name] = (boolean) $value;
                            break;

                        default:
                            require_once 'Zend/File/Transfer/Exception.php';
                            throw new Zend_File_Transfer_Exception("Unknown option: $name = $value");
                    }
                }
            }
        }

        return $this;
    }

The bug is in the line where $file is checked. The code:


...
        $file = $this->_getFiles($files, false, true);

        if (is_array($options)) {
            if ($file === null) { //the bug
                $this->_options = array_merge($this->_options, $options);
            }
...

Here $file is never null so the options passed to the Zend_File_Transfer_Adapter_Abstract are never applied.

The solution is:


...
        if (is_array($options)) {
            if (empty($file)) { //replacing $file === null with empty($file)
                $this->_options = array_merge($this->_options, $options);
            }
...

Comments

@Hristo Please, verify that you are using 1.10.2. This problem has been corrected in ZF-9159.

Not reproducable within 1.10.2

The given code does not exist within that release. Check if you are really using 1.10.2 and not another release.

Hi there,

You are right, when i checkout a clean copy of 1.10.2 release everything is OK.

Thank you for your response.