3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
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.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.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.