Browse Source

_hx_array_iterator now implements the PHP native interface Iterator

Franco Ponticelli 16 years ago
parent
commit
47e23d4032
1 changed files with 21 additions and 1 deletions
  1. 21 1
      std/php/Boot.hx

+ 21 - 1
std/php/Boot.hx

@@ -152,7 +152,7 @@ class _hx_array implements ArrayAccess {
 	}
 }
 
-class _hx_array_iterator {
+class _hx_array_iterator implements Iterator {
 	private $»a;
 	private $»i;
 	public function __construct($a) {
@@ -168,6 +168,26 @@ class _hx_array_iterator {
 	public function hasNext() {
 		return $this->»i < count($this->»a);
 	}
+
+	public function current() {
+		if (!$this->hasNext()) return false;
+		return $this->»a[$this->»i];
+	}
+
+	public function key() {
+		return $this->»i;
+	}
+
+	public function valid() {
+		return $this->current() !== false;
+	}
+
+	public function rewind() {
+		$this->»i = 0;
+	}
+	public function size() {
+		return count($this->»a);
+	}
 }
 
 function _hx_array_get($a, $pos) {