3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public $data = []; function __construct($data){ $this->data = $data; } function &getIterator() { foreach ($this->data as $key => &$value) { yield $key => $value; } } function printData() { foreach ($this->data as $key => $value) { echo($key . ':' . $value . PHP_EOL); } } } $data = array('one'=>'Curly', 'two'=>'Larry', 'three'=>'Moe'); $t = new Test($data); foreach ($t->getIterator() as $key => &$value) { $value = strtoupper($value); } $t->printData();

preferences:
67.94 ms | 402 KiB | 5 Q