3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace App\ServerArbiter; use App\ServerArbiter\Rules\Rule; /** * Class RuleSet * * @package App\ServerArbiter */ class RuleSet implements \Iterator { /** * @var Rule[] An array of Rule objects */ private $rules; /** * @var int Iterator position key */ private $position = 0; /** * @constructor */ public function __construct() { $this->position = 0; } /** * Add a Rule to the RuleSet * * @param Rule $rule */ public function addRule(Rule $rule) { if (!in_array($rule, $this->rules)) { $this->rules[] = $rule; } } /** * Remove a Rule from the RuleSet by it's key * * @param int $ruleKey The numeric key within the rules array to unset * * @throws \OutOfBoundsException When a non-existant key is provided * @throws \InvalidArgumentException When a non-integer parameter is provided */ public function removeRule($ruleKey) { if (is_int($ruleKey)) { if (array_key_exists($ruleKey, $this->rules)) { unset($this->rules[$ruleKey]); } else { throw new \OutOfBoundsException(sprintf( "%s was passed a out of bounds array key: %s does not exist in this ruleset", __METHOD__, $ruleKey )); } } else { throw new \InvalidArgumentException(sprintf( "%s expected an integer ruleKey parameter, got: '%s' instead", __METHOD__, $ruleKey )); } } /** * {@inheritdoc} * * @return Rule */ public function current() { return $this->rules[$this->position]; } /** * {@inheritdoc} */ public function next() { ++$this->position; } /** * {@inheritdoc} */ public function key() { return $this->position; } /** * {@inheritdoc} */ public function valid() { return isset($this->rules[$this->position]); } /** * {@inheritdoc} */ public function rewind() { $this->position = 0; } }
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: Return type of App\ServerArbiter\RuleSet::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 81 Deprecated: Return type of App\ServerArbiter\RuleSet::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 89 Deprecated: Return type of App\ServerArbiter\RuleSet::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 97 Deprecated: Return type of App\ServerArbiter\RuleSet::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 105 Deprecated: Return type of App\ServerArbiter\RuleSet::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/VnDHR on line 113
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 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/VnDHR 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/VnDHR on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/VnDHR on line 3
Process exited with code 255.

preferences:
225.13 ms | 401 KiB | 326 Q