The
IteratorAggregate<Tv> interface ¶
(HHVM >= 2.5)
Introduction ¶
Interface to create an external Iterator<Tv>.
Interface synopsis ¶
IteratorAggregate<Tv> extends Traversable<Tv> {
/* Methods */
}
Example
#1 Basic usage
<?hh
class myData<string> implements IteratorAggregate<string> {
public string $property1 = "Public property one";
public string $property2 = "Public property two";
public string $property3 = "Public property three";
// Using constructor promotion
public function __construct(public string $property) {
}
public function getIterator(): {
return new ArrayIterator($this);
}
}
$obj = new myData("last property");
foreach($obj as $value) {
var_dump($value);
echo "\n";
}
class myData<string> implements IteratorAggregate<string> {
public string $property1 = "Public property one";
public string $property2 = "Public property two";
public string $property3 = "Public property three";
// Using constructor promotion
public function __construct(public string $property) {
}
public function getIterator(): {
return new ArrayIterator($this);
}
}
$obj = new myData("last property");
foreach($obj as $value) {
var_dump($value);
echo "\n";
}
The above example will output something similar to:
string(19) "Public
property one"
string(19) "Public
property two"
string(21) "Public
property three"
string(13) "last
property"
Table of Contents ¶
·
IteratorAggregate<Tv>::getIterator — Retrieve an external iterator
IteratorAggregate<Tv>::getIterator
(HHVM >= 2.5)
IteratorAggregate<Tv>::getIterator — Retrieve an external iterator
Description ¶
abstract public Iterator<Tv> IteratorAggregate<Tv>::getIterator ( void )
Returns an external iterator.
Parameters ¶
This function has no parameters.
Return Values ¶
An instance of an object implementing Iterator<Tv>.
Errors/Exceptions ¶
No comments:
Post a Comment