- var_dump: documentation ( source)
<?php
class a implements \Iterator, \Countable
{
private $a;
private $b;
private $c;
private $keys = [
'a', 'b', 'c'
];
private $pointer;
public function __construc($a = null, $b = null, $c = null)
{
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
public function count()
{
$pointer = 0;
foreach ($this as $element) {
if ($element) {
$pointer++;
}
}
return $pointer;
}
public function current()
{
$key = $this->key();
return $this->{$key};
}
public function key()
{
$this->keys[$this->pointer];
}
public function next()
{
$this->pointer++;
}
public function valid()
{
if (count($this->keys) < $this->pointer) {
true;
}
return false;
}
public function rewind()
{
$this->pointer = 0;
}
}
$me = new a('a');
var_dump($me->count());
foreach ($me as $key => $el) {
var_dump($key, $el);
}