Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Fix] ArrayIterator::valid was incorrect

Summary:
ArrayIterator::valid was implemented as current() !== false, which would
incorrectly terminate when an element's value was false. Test key() !== null
instead (noting that keys cant be null).

Test Plan:
fast_tests, flib/type/dict

This is just a revert of a bogus change. Adding a new test case to prevent a
repeat.

<?php

function test($a) {
  $it = new ArrayIterator($a);
  while ($it->valid()) {
    var_dump($it->key());
    var_dump($it->current());
    $it->next();
  }
  }

test(array('a' => 'x',
           false => 'y',
           '1' => false,
           null => 'z',
           'c' => 'w'));

DiffCamp Revision: 144935
Reviewed By: hzhao
CC: hphp-diffs@lists, hzhao
Revert Plan:
OK
  • Loading branch information...
commit cf9b612ed0f96e223f4479672bdbe6b2fded49f9 1 parent 70aac14
@markw65 markw65 authored scottmac committed
Showing with 1 addition and 1 deletion.
  1. +1 −1  src/system/classes/iterator.php
View
2  src/system/classes/iterator.php
@@ -637,7 +637,7 @@ public function uksort($cmp_function) {
* @return mixed No value is returned.
*/
public function valid() {
- return current($this->arr) !== false;
+ return key($this->arr) !== null;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.