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 7648809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:48:37+00:00 2026-05-31T10:48:37+00:00

Let’s say I have following ArrayObject : $array_object = new ArrayObject(array( array(‘1’, ‘2’, ‘3’,

  • 0

Let’s say I have following ArrayObject:

$array_object = new ArrayObject(array(
   array('1', '2', '3', '4'),
   array('3', '6', '7', '8'),
   array('9', '3', '11', '12'),
));

And I extend RecursiveFilterIterator to accept only children elements which value is equal to some value passed in an argument:

class myRecursiveFilterIterator extends RecursiveFilterIterator
{
   public $value;

   public function __construct($it, $value)
   {
      parent::__construct($it);
      $this->value = $value;
   }

   public function accept()
   {
      return (parent::hasChildren()) || (parent::current() == $this->value);
   }
}

I create an instance of this brand new iterator, to filter values equal than 3:

$recursive_filter_iterator = new myRecursiveFilterIterator(new RecursiveArrayIterator($array_object), 3);

If now I loop the whole myRecursiveFilterIterator using an RecursiveIteratorIterator:

foreach (new RecursiveIteratorIterator($recursive_filter_iterator) as $value) {
   var_dump($value);
}

I get following warning:

Warning: Missing argument 2 for myRecursiveFilterIterator::__construct() in /my/path/test.php on line myLine Notice: Undefined variable: value in /my/path/test.php on line myOtherLine

So it’is like when looping RecursiveIteratorIterator is trying to instance myRecursiveFilterIterator without passing second argument $value.

This doesn’t happen if I extend FilterIterator without supplying extra arguments.

  • 1 1 Answer
  • 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-05-31T10:48:39+00:00Added an answer on May 31, 2026 at 10:48 am

    I decided to run the script my self and this is what have noticed

    1. you are working with multi array so parent::current() can be an array that means that
      the line below is wrong because $this->value is an integer.

      return (parent::hasChildren()) || (parent::current() == $this->value);
      
    2. $this->current () also switches String to Array you can do this to manage both depending on what you want to achieve

      if (is_array ( $current )) {
          return ($this->hasChildren ()) || (in_array ( ( string ) $this->value, $this->current () ));
      } else {
      
          //var_dump ( $this->value, $this->current () );
      
          return ($this->hasChildren ()) || ( $this->value == $this->current ());
      }
      
    3. You also need to implement getChildren method that is why PHP was complaining about Missing argument 2 for myRecursiveFilterIterator::__construct()

      public function getChildren() {
          return new self ( $this->getInnerIterator ()->getChildren (), $this->value );
      }
      

    ============================== DISCARD OLD RESPONSE =============================

    PHP most have communicated a wrong error message .. your code fine but the error originated when you tried to use foreach with RecursiveIteratorIterator directly

    Here is a better approach using RecursiveArrayIterator to encapsulate RecursiveIteratorIterator :

    foreach (new RecursiveArrayIterator(new RecursiveIteratorIterator($recursive_filter_iterator)) as $value) {
        var_dump($value);
    } 
    

    🙂

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say for example i have URL containing the following percent encoded character :
Let's say we have the following table: CREATE TABLE T ( ID INT, String1
Let's say we have following code: struct A{ virtual ~A(){} void f(){ p =

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.