- var_dump: documentation ( source)
<?php
class DataContainer implements IteratorAggregate { // create an external Iterator:
protected $data;
public function __construct(array $data) {
$this->data = $data;
}
public function &getIterator() {
static $times = 0;
foreach ($this->data as &$value) {
yield $value;
}
$times++;
echo "getting ext iterator - $times\n";
}
}
$dataContainer = new DataContainer([77, 78, 79]);
foreach ($dataContainer as &$value) {
echo $value *= -1,"\n";
}
//Must unset $value ...
foreach($dataContainer as $value);
var_dump($dataContainer);