3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Toolset\ChangeSet; /** * Class ChangeSet * * Represents a set of iteratable, countable Changes * * @package ChangeSet */ class ChangeSet implements \Iterator, \ArrayAccess, \Countable { /** * @var Change[] */ protected $changes = array(); /** * @var int Iterator position key */ private $position = 0; /** * Add a Change to the ChangeSet * * @param Change $change * * @throws ChangesetValidationException When a Change response with false to an isValid() call * * @return false When a change with the same id already exists */ public function addChange(Change $change) { if (!$change->isValid()) { throw new ChangeSetValidationException( sprintf("Attempted to add an invalid Change to a ChangeSet. Change: %s", $change) ); } foreach ($this->changes as $changeWeAlreadyHave) { if ($changeWeAlreadyHave->getId() === $change->getId()) { return false; } } $this->changes[] = $change; } /** * Remove a Change from the ChangeSet * * @param Change $change */ public function removeChange(Change $change) { array_walk($this->changes, function($changeToCheck, $key) use ($change) { /** @var Change $changeToCheck */ if ($changeToCheck->getId() === $change->getId()) { unset($this->changes[$key]); } }); } /** * Get changes * * @return Change[] */ public function getChanges() { return $this->changes; } /** * {@inheritdoc} * * @return Change */ public function current() { return $this->changes[$this->position]; } /** * {@inheritdoc} */ public function next() { ++$this->position; } /** * {@inheritdoc} */ public function key() { return $this->position; } /** * {@inheritdoc} */ public function valid() { return isset($this->changes[$this->position]); } /** * {@inheritdoc} */ public function rewind() { $this->position = 0; } /** * {@inheritdoc} */ public function count() { return count($this->changes); } /** * {@inheritdoc} */ public function offsetGet($offset) { return isset($this->changes[$offset]) ? $this->changes[$offset] : null; } /** * {@inheritdoc} */ public function offsetSet($offset, $value) { if (is_null($offset)) { $this->changes[] = $value; } else { $this->changes[$offset] = $value; } } /** * {@inheritdoc} */ public function offsetExists($offset) { return isset($this->changes[$offset]); } /** * {@inheritdoc} */ public function offsetUnset($offset) { unset($this->changes[$offset]); } }
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Deprecated: Return type of Toolset\ChangeSet\ChangeSet::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XOG60 on line 77 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XOG60 on line 84 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XOG60 on line 91 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XOG60 on line 98 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XOG60 on line 105 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::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/XOG60 on line 140 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::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/XOG60 on line 119 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::offsetSet($offset, $value) 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/XOG60 on line 126 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::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/XOG60 on line 147 Deprecated: Return type of Toolset\ChangeSet\ChangeSet::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XOG60 on line 112
Output for 5.3.0 - 5.3.29, 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
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/XOG60 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/XOG60 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/XOG60 on line 3
Process exited with code 255.

preferences:
93.9 ms | 2498 KiB | 4 Q