{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zend-inputfilter/issues/6","labels_url":"https://api.github.com/repos/zendframework/zend-inputfilter/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zend-inputfilter/issues/6/comments","events_url":"https://api.github.com/repos/zendframework/zend-inputfilter/issues/6/events","html_url":"https://github.com/zendframework/zend-inputfilter/issues/6","id":87745959,"number":6,"title":"Can't create optional input","user":{"login":"svycka","id":1270782,"avatar_url":"https://avatars.githubusercontent.com/u/1270782?v=3","gravatar_id":"","url":"https://api.github.com/users/svycka","html_url":"https://github.com/svycka","followers_url":"https://api.github.com/users/svycka/followers","following_url":"https://api.github.com/users/svycka/following{/other_user}","gists_url":"https://api.github.com/users/svycka/gists{/gist_id}","starred_url":"https://api.github.com/users/svycka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svycka/subscriptions","organizations_url":"https://api.github.com/users/svycka/orgs","repos_url":"https://api.github.com/users/svycka/repos","events_url":"https://api.github.com/users/svycka/events{/privacy}","received_events_url":"https://api.github.com/users/svycka/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zendframework/zend-inputfilter/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-12T14:26:52Z","updated_at":"2015-06-12T18:04:49Z","closed_at":"2015-06-12T15:22:46Z","body":"I need an optional input lets say I expect data like `{name: \"some name\", age: 18}` or `{name: \"some name\"}` but don't want `{name: \"some name\" age: null}` and this is impossible to do now or I can't find a way how to do it.\r\nAs an example I wrote a test for this, of course this does not pass:\r\n```php\r\nclass OptionalInputTest extends PHPUnit_Framework_TestCase\r\n{\r\n    /**\r\n     * @dataProvider dataProvider\r\n     */\r\n    public function testNewFeature($data, $isValid)\r\n    {\r\n        $inputFilter = new \\Zend\\InputFilter\\InputFilter();\r\n        $inputFilter->add([\r\n            'name' => 'foo',\r\n            'required' => false,\r\n            'allow_empty' => false,\r\n            'continue_if_empty' => true,\r\n            'validators' => [\r\n                ['name' => 'StringLength', 'options' => ['min' => 2]],\r\n            ],\r\n        ]);\r\n\r\n        $inputFilter->setData($data);\r\n\r\n        if ($isValid) {\r\n            $this->assertTrue($inputFilter->isValid());\r\n        } else {\r\n            $this->assertFalse($inputFilter->isValid());\r\n        }\r\n    }\r\n\r\n    public function dataProvider()\r\n    {\r\n        return [\r\n            [['foo' => null], false],\r\n            [['foo' => ''], false],\r\n            [[], true],\r\n            [['foo' => \"bar\"], true]\r\n        ];\r\n    }\r\n}\r\n```\r\nMaybe I overthinking this? "},"comment":{"url":"https://api.github.com/repos/zendframework/zend-inputfilter/issues/comments/111576728","html_url":"https://github.com/zendframework/zend-inputfilter/issues/6#issuecomment-111576728","issue_url":"https://api.github.com/repos/zendframework/zend-inputfilter/issues/6","id":111576728,"user":{"login":"svycka","id":1270782,"avatar_url":"https://avatars.githubusercontent.com/u/1270782?v=3","gravatar_id":"","url":"https://api.github.com/users/svycka","html_url":"https://github.com/svycka","followers_url":"https://api.github.com/users/svycka/followers","following_url":"https://api.github.com/users/svycka/following{/other_user}","gists_url":"https://api.github.com/users/svycka/gists{/gist_id}","starred_url":"https://api.github.com/users/svycka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svycka/subscriptions","organizations_url":"https://api.github.com/users/svycka/orgs","repos_url":"https://api.github.com/users/svycka/repos","events_url":"https://api.github.com/users/svycka/events{/privacy}","received_events_url":"https://api.github.com/users/svycka/received_events","type":"User","site_admin":false},"created_at":"2015-06-12T18:04:49Z","updated_at":"2015-06-12T18:04:49Z","body":"I understand that this is almost the same but for me it is BC because before this https://github.com/zendframework/zend-inputfilter/issues/4 it was possible to do this.\r\nAnd now I will have to move this check from input filter to maybe hydrator because:\r\n```php\r\n// when ['foo' => null]\r\n$filter->getData(); // returns ['foo' => null]\r\n// when ['foo' => '']\r\n$filter->getData(); // returns ['foo' => '']\r\n// when []\r\n$filter->getData(); // returns []\r\n```\r\nthey all are considred empty and when I pass this data to hydrator null and '' are run by hydrator but last one is ignored.\r\n@weierophinney how could I solve this with inputfilter?"}}