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

Issue Type: Bug Created: 2011-03-09T08:16:10.000+0000 Last Updated: 2012-06-02T12:13:30.000+0000 Status: Closed Fix version(s): - 1.11.12 (22/Jun/12)

  • Next Major Release ()

Reporter: Björn Rylander (hasslarp) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Form

Related issues: Attachments:


The following code makes getFileName return an empty array.

<pre class="highlight">
    $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.


Posted by Adam Lundrigan (adamlundrigan) on 2011-04-30T07:36:22.000+0000

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:

<pre class="highlight">
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.

Posted by Thomas Weidner (thomas) on 2011-05-01T07:03:06.000+0000

Reassigning to component author

Posted by Adam Lundrigan (adamlundrigan) on 2011-05-03T14:05:19.000+0000

Patch applied to trunk r23963

Posted by Thomas Weidner (thomas) on 2011-05-03T14:26:44.000+0000

Adam, thnx for your fix

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

Posted by Adam Lundrigan (adamlundrigan) on 2011-06-24T15:44:35.000+0000

Merged documentation change to release-1.11 in r24153

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-18T12:13:17.000+0000

Thomas: Is it safe to close this issue now?

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.