title: PHP Iterator interface: current() returns underlying array instead of first value
body: <p>I'm creating a class that implements <code>Iterator</code> and <code>ArrayAccess</code>. The iterator tests are failing. When I do a <code>print_r()</code> on <code>current($object)</code>, I get the underlying array, not the first object. </p>
  
  <p>The code below is a sample from my actual class that demonstrates the issue. This is the first time I have implemented <code>Iterator</code> in one of my classes, so I'm probably doing this wrong somewhere. What do I need to change to make the iterator work properly? </p>
  
  <p>Code:</p>
  
  <pre><code>class Collection implements \ArrayAccess, \Iterator
  {
      private $_array = array();
  
      public function __invoke() { return $this-&gt;_array; }
      public function offsetExists($offset) { return array_key_exists($offset, $this-&gt;_array); }
      public function offsetGet($offset) { return $this-&gt;_array[$offset]; }
      public function offsetSet($offset, $value) { $this-&gt;_array[$offset] = $value; }
      public function offsetUnset($offset) { unset($this-&gt;_array[$offset]); }
      public function current() { return current($this-&gt;_array); }
      public function key() { return key($this-&gt;_array); }
      public function next() { return next($this-&gt;_array); }
      public function rewind() { return reset($this-&gt;_array); }
      public function valid() { return is_null(key($this-&gt;_array)); }
  }
  
  class TemporaryTest extends \PHPUnit\Framework\TestCase
  {
  
      private $_test_object;
  
      public function setUp()
      {
          $this-&gt;_test_object = new Collection();
          $this-&gt;_test_object['alpha'] = 'blah';
          $this-&gt;_test_object['beta'] = 'yada';
          $this-&gt;_test_object['gamma']  = 'woot';
      }
  
      public function testIteratorOnInternalArray()
      {
          $o = $this-&gt;_test_object;
          $a = $o();
          $this-&gt;assertEquals('blah', current($a));
          $this-&gt;assertEquals('yada', next($a));
          $this-&gt;assertEquals('woot', next($a));
      }
  
      public function testIterator()
      {
          print_r(current($this-&gt;_test_object));
          $this-&gt;assertEquals('blah', current($this-&gt;_test_object));
          $this-&gt;assertEquals('yada', next($this-&gt;_test_object));
          $this-&gt;assertEquals('woot', next($this-&gt;_test_object));
          $this-&gt;assertFalse($this-&gt;_test_object-&gt;valid());
          reset($this-&gt;_test_object);
          $this-&gt;assertEquals('blah', current($this-&gt;_test_object));
      }
  
      public function testForEach()
      {
          $actual = array();
          foreach ($this-&gt;_test_object as $key =&gt; $value) { $actual[$key] = $value; }
          $this-&gt;assertEquals(array('alpha' =&gt; 'blah', 'beta' =&gt; 'yada','gamma' =&gt;  'woot'), $actual);
      }
  }
  </code></pre>
  
  <p>Unit test output:</p>
  
  <pre><code>.FArray
  (
      [alpha] =&gt; blah
      [beta] =&gt; yada
      [gamma] =&gt; woot
  )
  F                                                                 3 / 3 (100%)
  
  There were 2 failures:
  
  1) TemporaryTest::testIterator
  Array (...) does not match expected type "string".
  
  /Users/mac/Projects/NetShapers/Gears/core/Tests/Unit/TemporaryTest.php:83
  
  2) TemporaryTest::testForEach
  Failed asserting that two arrays are equal.
  --- Expected
  +++ Actual
  @@ @@
   Array (
  -    'alpha' =&gt; 'blah'
  -    'beta' =&gt; 'yada'
  -    'gamma' =&gt; 'woot'
   )
  
  /Users/mac/Projects/NetShapers/Gears/core/Tests/Unit/TemporaryTest.php:97
  </code></pre>