3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Entity { protected $_properties = []; public function &__get($property) { $value = null; return $value; } public function __set($property, $value) { $property = [$property => $value]; foreach ($property as $p => $value) { $this->_properties[$p] = $value; } } } class CustomIterator extends IteratorIterator { public $callback; public function __construct($items) { $this->callback = function ($a) { $a->foo .= ' world'; return $a; }; parent::__construct($items); } public function current() { $c = $this->callback; return $c(parent::current()); } } $entity = new Entity(); $it = new CustomIterator(new ArrayIterator([$entity])); $it->rewind(); var_dump($it->current());

preferences:
57.68 ms | 402 KiB | 5 Q