<?php
class myIterator implements Iterator
{
private $position = 0;
private $array = array(
"firstelement_Iterator",
"secondelement_Iterator",
"lastelement_Iterator",
);
public function __construct() {
$this->position = 0;
}
function rewind() {
$this->position = 0;
}
function current() {
return $this->array[$this->position];
}
function key() {
return $this->position;
}
function next() {
++$this->position;
}
function valid() {
return isset($this->array[$this->position]);
}
}
$test = new myIterator();
echo "start test $testName\n";
$current = current($test);
$i = 0;
$current = current($test);
foreach ($test as $key => $value) {
//echo "$key, $value \n";
}
//current returns the value of the array element that's currently being pointed to by the
// internal pointer.
// If the internal pointer points beyond the end of the elements list or the array is empty, current() returns FALSE.
var_dump(current($test));
// reset() rewinds array's internal pointer to the first element and
// returns the value of the first array element - this should be firstelement_*
var_dump(reset($test));
echo "End test.\n\n";
Deprecated: Return type of myIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/C6MvK on line 21
Deprecated: Return type of myIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/C6MvK on line 29
Deprecated: Return type of myIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/C6MvK on line 25
Deprecated: Return type of myIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/C6MvK on line 33
Deprecated: Return type of myIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/C6MvK on line 17
Warning: Undefined variable $testName in /in/C6MvK on line 46
start test
Deprecated: current(): Calling current() on an object is deprecated in /in/C6MvK on line 48
Deprecated: current(): Calling current() on an object is deprecated in /in/C6MvK on line 51
Deprecated: current(): Calling current() on an object is deprecated in /in/C6MvK on line 59
int(3)
Deprecated: reset(): Calling reset() on an object is deprecated in /in/C6MvK on line 62
int(3)
End test.
Output for 8.0.0 - 8.0.30
Warning: Undefined variable $testName in /in/C6MvK on line 46
start test
int(3)
int(3)
End test.