title: How to pass a variable by reference when creating an object in php
body: <p>So I want to extend for example this <a href="http://www.php.net/manual/en/class.recursivearrayiterator.php" rel="nofollow">RecursiveIterator from the SPL</a> with the function each so i can easily walk over the object/array</p>
  
  <pre><code>class it extends RecursiveArrayIterator {
      public function each( $function, $args=array() ){
          $args = (sizeof($args)&gt;0) ? array_merge(array($this),(array)$args) : array($this);
          iterator_apply( $this, $function, $args );
          return $this;
      }
  }
  //Running it:
  $it = new it( &amp;$array );
  $it-&gt;each( function( $it ){
      $it-&gt;offsetSet( $it-&gt;key(),  $it-&gt;current() + 1 );
      return true;
  });
  </code></pre>
  
  <p>Which results in:</p>
  
  <blockquote>
    <p>Deprecated: Call-time pass-by-reference has been deprecated in ...</p>
  </blockquote>
  
  <p>The problem is i can't, or shouldn't, use the reference when creating the object because its depricated. But when iterating over the array/object i want to be able to make changes to it, how can i achieve this without changing the <code>allow_call_time_pass_reference</code> to <code>On</code>? I'm using wamp with php 5.3.</p>
  
  <p>Have a nice day</p>
  
  <p><a href="http://www.php.net/manual/en/class.recursivearrayiterator.php" rel="nofollow">1</a>: <a href="http://www.php.net/manual/en/class.recursivearrayiterator.phpin" rel="nofollow">http://www.php.net/manual/en/class.recursivearrayiterator.phpin</a> ...</p>