Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

BC-Break in 2.4.1? Really annoying NotEmpty injection by default #4

Closed
@manuakasam

Description

@manuakasam

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 ^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions