3v4l.org

run code in 300+ PHP versions simultaneously
<?php class UBuffer implements IteratorAggregate, Countable { public function __construct($input) { for ($it = 0; $it < mb_strlen($input); $it++) { $this->buffer[$it] = mb_substr($input, $it, 1); } } 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: $this->buffer[$count] = new UBuffer($this->buffer[$count]); $count++; break; } } if (!$this->buffer[$count] instanceof UBuffer) $this->buffer[$count] = new UBuffer($this->buffer[$count]); } 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 git.master, git.master_jit, rfc.property-hooks
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/Nk4fe on line 10 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/Nk4fe on line 11 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/Nk4fe on line 44 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/Nk4fe on line 45 object(UBuffer)#6 (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)#5 (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:
72.58 ms | 2246 KiB | 4 Q