3v4l.org

run code in 300+ PHP versions simultaneously
<?php class UBuffer implements ArrayAccess, IteratorAggregate, Countable { public function __construct($input) { for ($it = 0; $it < mb_strlen($input); $it++) { $this->buffer[$it] = mb_substr($input, $it, 1); } } public function offsetGet($offset) { return $this->buffer[$offset]; } public function offsetUnset($offset) { throw new RuntimeException("NOPE"); } public function offsetSet($offset, $char) { throw new RuntimeException("NOPE"); } public function offsetExists($offset) { return isset($this->buffer[$offset]); } public function getIterator() { return new ArrayIterator($this->buffer); } public function count() { return count($this->data); } private $buffer; } class UBreaker implements IteratorAggregate, Countable { const KEEP = 1; const NEXT = 2; public function __construct(UBuffer $buffer, Closure $breaker) { $count = 0; $mem = null; foreach ($buffer as $idx => $char) { switch ($breaker($buffer, $idx, $char, $mem)) { case self::KEEP: if (isset($this->buffer[$count])) $this->buffer[$count] .= $char; else $this->buffer[$count] = $char; break; case self::NEXT: $count++; break; } } foreach ($this->buffer as $idx => $value) $this->buffer[$idx] = new UBuffer($value); } public function getIterator() { return new ArrayIterator($this->buffer); } public function count() { return count($this->buffer); } private $buffer; } $buffer = new UBuffer("This is a simple sentence. And here's another one."); $breaker = new UBreaker($buffer, function(UBuffer $buffer, $index, $char, &$mem) { switch ($char) { case " ": switch ($mem) { case ".": case "!": case "?": $mem = $char; return UBreaker::NEXT; } default: $mem = $char; return UBreaker::KEEP; } }); foreach ($breaker as $sentence) { var_dump($sentence); } ?>
Output for rfc.property-hooks, git.master, git.master_jit
Deprecated: Return type of UBuffer::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7Yuf9 on line 13 Deprecated: Return type of UBuffer::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7Yuf9 on line 10 Deprecated: Return type of UBuffer::offsetSet($offset, $char) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7Yuf9 on line 12 Deprecated: Return type of UBuffer::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7Yuf9 on line 11 Deprecated: Return type of UBuffer::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7Yuf9 on line 15 Deprecated: Return type of UBuffer::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7Yuf9 on line 17 Deprecated: Return type of UBreaker::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7Yuf9 on line 48 Deprecated: Return type of UBreaker::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7Yuf9 on line 52 object(UBuffer)#5 (1) { ["buffer":"UBuffer":private]=> array(26) { [0]=> string(1) "T" [1]=> string(1) "h" [2]=> string(1) "i" [3]=> string(1) "s" [4]=> string(1) " " [5]=> string(1) "i" [6]=> string(1) "s" [7]=> string(1) " " [8]=> string(1) "a" [9]=> string(1) " " [10]=> string(1) "s" [11]=> string(1) "i" [12]=> string(1) "m" [13]=> string(1) "p" [14]=> string(1) "l" [15]=> string(1) "e" [16]=> string(1) " " [17]=> string(1) "s" [18]=> string(1) "e" [19]=> string(1) "n" [20]=> string(1) "t" [21]=> string(1) "e" [22]=> string(1) "n" [23]=> string(1) "c" [24]=> string(1) "e" [25]=> string(1) "." } } object(UBuffer)#4 (1) { ["buffer":"UBuffer":private]=> array(23) { [0]=> string(1) "A" [1]=> string(1) "n" [2]=> string(1) "d" [3]=> string(1) " " [4]=> string(1) "h" [5]=> string(1) "e" [6]=> string(1) "r" [7]=> string(1) "e" [8]=> string(1) "'" [9]=> string(1) "s" [10]=> string(1) " " [11]=> string(1) "a" [12]=> string(1) "n" [13]=> string(1) "o" [14]=> string(1) "t" [15]=> string(1) "h" [16]=> string(1) "e" [17]=> string(1) "r" [18]=> string(1) " " [19]=> string(1) "o" [20]=> string(1) "n" [21]=> string(1) "e" [22]=> string(1) "." } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
118.33 ms | 3328 KiB | 4 Q