3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TrimIterator extends IteratorIterator { public function current() { return trim(parent::current()); } } $innerIterator = new ArrayIterator(array('normal', ' trimmable ')); $trim = new TrimIterator($innerIterator); foreach ($trim as $key => $value) { echo "Key:\n"; var_dump($key); echo "Value:\n"; var_dump($value); echo "---next---"; }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of TrimIterator::current() should either be compatible with IteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Y2CVd on line 5 Key: int(0) Value: string(6) "normal" ---next---Key: int(1) Value: string(9) "trimmable" ---next---
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Key: int(0) Value: string(6) "normal" ---next---Key: int(1) Value: string(9) "trimmable" ---next---

preferences:
185.1 ms | 404 KiB | 274 Q