Browse Source

[Php] Array.filter fix (fixed issue #1477)

Simon Krajewski 12 years ago
parent
commit
f192aeb8a0
2 changed files with 6 additions and 1 deletions
  1. 1 1
      std/php/Boot.hx
  2. 5 0
      tests/unit/unitstd/Array.unit.hx

+ 1 - 1
std/php/Boot.hx

@@ -160,7 +160,7 @@ class _hx_array implements ArrayAccess, IteratorAggregate {
 	}
 	}
 
 
 	function filter($f) {
 	function filter($f) {
-		return new _hx_array(array_filter($this->a,$f));
+		return new _hx_array(array_values(array_filter($this->a,$f)));
 	}
 	}
 
 
 	// ArrayAccess methods:
 	// ArrayAccess methods:

+ 5 - 0
tests/unit/unitstd/Array.unit.hx

@@ -229,6 +229,11 @@ var func = function(s) return s.toUpperCase();
 [1, 2, 3, 4].filter(function(i) return false) == [];
 [1, 2, 3, 4].filter(function(i) return false) == [];
 [].filter(function(i) return true) == [];
 [].filter(function(i) return true) == [];
 [].filter(function(i) return false) == [];
 [].filter(function(i) return false) == [];
+var arr = [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}];
+arr = arr.filter(function(i) return i.id % 2 != 0);
+var values = [];
+for (a in arr) values.push(a.id);
+values == [1, 3, 5];
 
 
 #if !as3
 #if !as3
 // check that map and filter work well on Dynamic as well
 // check that map and filter work well on Dynamic as well