3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace App\ServerArbiter; use App\ServerArbiter\Rules\Rule, App\Model\Entity\Server; /** * Class ServerArbiter * * @package App\ServerArbiter */ class ServerArbiter { /** * @var RuleSet */ private $ruleSet; /** * @var Server[] */ private $servers; public function __construct(RuleSet $ruleSet, array $servers) { foreach ($servers as $server) { if (!($server instanceof Server)) { throw new \InvalidArgumentException(sprintf( "Second parameter for: %s must be an array of Server objects. %s given which is an instance of %s.", __METHOD__, $server, is_scalar($server) ? 'a scalar value' : get_class($server) )); } } $this->ruleSet = $ruleSet; $this->servers = $servers; } /** * Run each Server against each Rule in the RuleSet and return the Server that matched the most rules * * @return Server The Server chosen by the ServerArbiter * * @note If two servers match the same number of rules successfully, the first one will be returned */ public function decide() { $decisions = []; /** @var Rule $rule */ foreach ($this->ruleSet as $rule) { foreach ($this->servers as $server) { if (!array_key_exists($server->getId(), $decisions)) { $decisions[$server->getId()]['successes'] = 0; } if ($rule->resolve()) { $decisions[$server->getId()]['successes']++; } } } $decision = array_search(max($decisions), $decisions); return $decision; } }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 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, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/IF1gb on line 51
Process exited with code 255.
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/IF1gb 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/IF1gb on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/IF1gb on line 3
Process exited with code 255.

preferences:
304.62 ms | 401 KiB | 456 Q