3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php namespace Rixxi\Utils; class Batch implements \ArrayAccess { /** @var int */ private $limit; /** @var int */ private $counter = 0; /** @var callable */ private $callback; /** @var array */ private $values = array(); /** * @param callable $callback * @param int $limit */ public function __construct(callable $callback, $limit = 1000) { $this->callback = $callback; $this->limit = $limit; } public function __destruct() { $this->flush(); } public function add($value) { $this->values[] = $value; if (++$this->counter === $this->limit) { $this->flush(); } } public function flush() { if ($this->counter !== 0) { $callback = $this->callback; $callback($this->values); $this->values = []; $this->counter = 0; } } public function offsetSet($index, $value) { if ($index !== NULL) { throw new } $this->add($value); } public function offsetGet($index) { throw new NotSupportedException('You can only append to batch.'); } public function offsetExists($index) { throw new NotSupportedException('You can only append to batch.'); } public function offsetUnset($index) { throw new NotSupportedException('You can only append to batch.'); } }
Output for 5.4.0 - 5.5.12
Parse error: syntax error, unexpected '}' in /in/ufCQN on line 63
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected '[' in /in/ufCQN on line 53
Process exited with code 255.