zendframework / zend-form

Form component from Zend Framework
BSD 3-Clause "New" or "Revised" License
69 stars 87 forks source link

Updated Form class, bindValues function to set to empty array if no … #216

Closed rkeet closed 5 years ago

rkeet commented 6 years ago

Updated Form class, bindValues function to set to empty array if no data to pass along for baseFieldset

Provide a narrative description of what you are trying to accomplish:

In detail: https://github.com/zendframework/zend-form/issues/215

In short:

Form->bindValues($data, ...) calls Fieldset->bindValues($data, ...).

Fieldset has the function defined as:

public function bindValues(array $values = [], array $validationGroup = null)

The $data var was set with the following line:

$data = $data[$this->baseFieldset->getName()];

In the case of no defined Input elements, this may cause there to be no key with that name and have the $data variable be null. This then causes a fatal error when Form->bindValues($data, ...) calls Fieldset->bindValues($data, ...)


In respect, I've assumed that no tests need to be modified (they pass btw, though there's 40'ish that don't run because they're for Annotation) as this function was assumed to work with the happy-flow of properly calling the Fieldset->bindValues() function. This change just catches a bug but does not modify the intended functionality (I think).

froschdesign commented 6 years ago

@rkeet

In respect, I've assumed that no tests need to be modified

But we need an unit test to cover your scenario.

rkeet commented 6 years ago

Created a test case for the scenario. Am tired though, so please check it as well. More another day.

weierophinney commented 5 years ago

Thanks, @rkeet!