Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158809

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:20:18+00:00 2026-06-17T13:20:18+00:00

I’m using Zend_Filter_Input to filter and validate my data. For a field (gender), I

  • 0

I’m using Zend_Filter_Input to filter and validate my data. For a field (gender), I am using the Zend_Validate_InArray to validate, if the value is in

array('m', 'w');

So far so good.
While running my UnitTests, I noticed, that an empty array is a valid value for gender, too.
To analyze this, I wrote the following code:

$genderArray = array('m', 'w');
$needle = array();
if(in_array($needle, $genderArray)) {
    Zend_Debug::dump('is in array');
} else {
    Zend_Debug::dump('is not in array');
}

$validator = new Tueks_Validate_InArray($genderArray);
if ($validator->isValid($needle)) {
    Zend_Debug::dump('is in array');
} else {
    Zend_Debug::dump('is not in array');
}

Both times, I got ‘is not in array’.

But when I use the following code:

$child = new Tueks_Placereport_Child();
$child->setGender($needle);
$child->validate();

everything works fine (–> array() ist part of array(‘m’, ‘w’))?!?

Here is the relevant part from my validate-method:

$genderArray = array('m', 'w');
$filters = array();
$validators = array('gender'=> 
                     array('presence'=> 'required',
                           new Tueks_Validate_InArray($genderArray)
                          )
                   );
$input = new Zend_Filter_Input($filters, $validators, $this->_data);

Tueks_Validate_InArray is the same like Zend_Validate_InArray, but with other messages.
I don’t see the problem, why, when using Zend_Filter_Input, an empty array is a valid value.
Hope you can help me.

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:20:20+00:00Added an answer on June 17, 2026 at 1:20 pm

    This actually is a bug in Zend Framework thas has not been fixed as of yet. And as Zend_Filter_Input has been discontinued with Zend Framework 2, I’ll highly doubt that it will ever be. However, there is a patch attached to the ticket that should resolve this issue.

    I also did a little debugging and could track it down to the method _validateRule in Zend_Filter_Input:

    There you can find this code block:

    if (!is_array($field)) {
        $field = array($field);
    }
    [...]
    foreach ($field as $key => $value) {
    [...]
        if (!$validatorChain->isValid($value)) {
    

    $field contains the value of the field. As you can see, if you pass a non-array value, it is put into an array, so that the foreach block is entered. However, if you pass an empty array, then $field will stay array(0) {} and therefore the whole foreach block will not be entered. Therefore not a single validation (nor a non-empty check) will be exectued.

    I also tried to find a workaround, but they are all rather awkward. Therefore, the most simple workaround for this would be to check if $value is an empty array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am confused How to use looping for Json response Array in another Array.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.