BC-Break in 2.4.1? Really annoying NotEmpty injection by default #4
Description
Hey guys, I've run into troubles at work with our InputFilters behaving very weird when updating from 2.4.0 to 2.4.2. The change that gave us trouble actually happened in 2.4.1 and it's been this one right here:
zendframework/zendframework#7474
zendframework/zendframework@ffad792#diff-eba196bb0648a9366fa5c59a0edb701b
public function setRequired($required)
{
$this->required = (bool) $required;
- $this->setAllowEmpty(!$required);
return $this;
}
The removal of this little snippet has led to the injection of the NotEmpty
validator by default. I have created a little test to outline my problem:
public function testWtf()
{
$data = [
'foo' => '0'
];
$inputFilter = new InputFilter();
$inputFilter->add([
'name' => 'foo',
'required' => false,
'filters' => [
['name' => 'Boolean']
],
'validators' => []
]);
$inputFilter->setData($data);
$this->assertTrue($inputFilter->isValid());
}
This is basically how I wrote the InputFilter. Now knowing the internals of the InputFilter (after doing some digging), i now know that I can simply workaround this by adding allow_empty => true
to the inputFilter configuration, but I'm asking myself "why?".
2.4.1 had only Bugfixes but in my opinion this is clearly a BC Break as it is breaking existing stuff.
I'm trying to figure out the reasoning for having the NotEmpty
validator be added by default. So if anyone could elaborate on this, that'd probably be a huge help to me.
Aside from this, but this may be offtopic to this component:
why is NotEmpty behaving the way it is? Why is 0
or false
be considered empty be default?
Those two things combined are really tricky to get around and I'm using this framework pretty regularly ^^