<?php
class XRange implements Iterator
{
protected $value = 0;
protected $limit;
protected $step;
protected $initial;
protected $key = 0;
public function __construct($value, $limit, $step = 1)
{
$this->value = $this->initial = $value;
$this->limit = $limit;
$this->step = $step;
}
{
$this->value = $this->initial;
}
{
return $this->value;
}
{
$this->value += $this->step;
}
public function valid()
{
return $this->value <= $this->limit;
}
{
}
}
foreach(new XRange(1, 10, 1) as $value) {
echo $value;
}
PD9waHAKCgpjbGFzcyBYUmFuZ2UgaW1wbGVtZW50cyBJdGVyYXRvcgp7Cglwcm90ZWN0ZWQgJHZhbHVlID0gMDsKCglwcm90ZWN0ZWQgJGxpbWl0OwoKCXByb3RlY3RlZCAkc3RlcDsKCglwcm90ZWN0ZWQgJGluaXRpYWw7CgoJcHJvdGVjdGVkICRrZXkgPSAwOwoKCXB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkdmFsdWUsICRsaW1pdCwgJHN0ZXAgPSAxKQoJewoJCSR0aGlzLT52YWx1ZSA9ICR0aGlzLT5pbml0aWFsID0gJHZhbHVlOwoKCQkkdGhpcy0+bGltaXQgPSAkbGltaXQ7CgoJCSR0aGlzLT5zdGVwID0gJHN0ZXA7Cgl9CgoJcHVibGljIGZ1bmN0aW9uIHJld2luZCgpCgl7CgkJJHRoaXMtPnZhbHVlID0gJHRoaXMtPmluaXRpYWw7Cgl9CgoJcHVibGljIGZ1bmN0aW9uIGN1cnJlbnQoKQoJewoJCXJldHVybiAkdGhpcy0+dmFsdWU7Cgl9CgoJcHVibGljIGZ1bmN0aW9uIG5leHQoKQoJewoJCSR0aGlzLT52YWx1ZSArPSAkdGhpcy0+c3RlcDsKCgkJKyskdGhpcy0+a2V5OwoJfQoKCXB1YmxpYyBmdW5jdGlvbiB2YWxpZCgpCgl7CgkJcmV0dXJuICR0aGlzLT52YWx1ZSA8PSAkdGhpcy0+bGltaXQ7Cgl9CgoJcHVibGljIGZ1bmN0aW9uIGtleSgpCgl7CgkJcmV0dXJuICR0aGlzLT5rZXk7Cgl9Cn0KCgpmb3JlYWNoKG5ldyBYUmFuZ2UoMSwgMTAsIDEpIGFzICR2YWx1ZSkgewoKCWVjaG8gJHZhbHVlOwp9