ZF-11152: Zend_Form_Element_File::getFileName() returns array if empty


The following code makes getFileName return an empty array.

    $uploadedData = $form->getValues();
    $element = new Zend_Form_Element_File("element_name");
    $fileName = $element->getFileName();

This is when the no file is supplied and element has setValueDisabled(true) in the form and it's not set to required. The documentation says Zend_Form_Element_File::getFileName() is to return a string.


I'm fairly confident this type of change would be considered a BC break. A return type of array() when no file fields with the specified name were uploaded is not ideal, but nonetheless is acceptable. The documentation should be updated to make note of the current behavior of getFileName() - here is my take on how that could be done:

Return value of getFileName()
        The result returned by the getFileName() method will change depending on how many files the Zend_Form_Element_File uploaded:
                A single file: string containing the single file name.
                Multiple files: an array, where each item is a string containing a single file name.
                No files: an empty array

The PHP function empty() treats empty strings, null and array() the same - empty. So, to find out if no files were returned you do: empty($element->getFileName()). This will cover off all the ways getFileName() could report that there are no files.

Reassigning to component author

Patch applied to trunk r23963

Adam, thnx for your fix

Please do actually not close this issue as this component is being reworked. This is intentionally Thnx

Merged documentation change to release-1.11 in r24153

Thomas: Is it safe to close this issue now?