3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface PolicyRule { public function isSatisfiedBy(string $aValue); } class CredentialPolicy implements PolicyRule { private $maximumDaysOld; private $policyRules; public function __construct(PolicyRule[] $aPolicyRuleSet) { $this->policyRules = $aPolicyRuleSet; } public function isSatisfiedBy(string $aCredential) : bool { foreach ($this->policyRules as $rule) { if (! $rule->isSatisfiedBy($aCredential)) { return false; } } return true; } } abstract class EnforcedRule implements PolicyRule { const UNENFORCED = 0; const ENFORCED = 1; private $enforcementType; protected function isEnforced() : bool { return ($this->enforcementType == self::ENFORCED); } protected function setEnforcementType(int $aType) { $this->guardEnforcementType($aType); $this->enforcementType = $aType; } protected function guardEnforcementType(int $aType) { if (! in_array($aType, [self::UNENFORCED, self::ENFORCED])) { throw new InvalidEnforcementTypeException($aType); } } } abstract class MinimumCharacterCountRule extends EnforcedRule { const DEFAULT_MINIMUM = 1; protected $regexPattern; protected $minimumCount = self::DEFAULT_MINIMUM; public function isSatisfiedBy(string $aValue) : bool { if (! $this->isEnforced()) { return true; } $matches = []; preg_match_all($this->regexPattern, $aValue, $matches); return (count($matches[0]) >= $this->minimumCount); } } class NumericRule extends MinimumCharacterCountRule { protected $regexPattern = '/[0-9]/'; public function __construct(int $aMinimumCount = self::DEFAULT_MINIMUM, int $anEnforcementType = self::ENFORCED) { $this->setEnforcementType($anEnforcementType); $this->minimumCount = $aMinimumCount; } } class SpecialCharacterRule extends MinimumCharacterCountRule { protected $regexPattern = '/[~`#\$%\^&\*\(\)\-_\+\|,\.<>]/'; public function __construct(int $aMinimumCount = self::DEFAULT_MINIMUM, int $anEnforcementType = self::ENFORCED) { $this->setEnforcementType($anEnforcementType); $this->minimumCount = $aMinimumCount; } } $policy = new CredentialPolicy([ new NumericRule(), new SpecialCharacterRule() ]); var_dump($policy->isSatisfiedBy("for5"));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.6.150.0130.07718.19
5.6.140.0030.07018.18
5.6.130.0070.07018.23
5.6.120.0170.06721.00
5.6.110.0100.08321.05
5.6.100.0070.04021.11
5.6.90.0070.04320.98
5.6.80.0030.05320.38
5.5.300.0070.07017.97
5.5.290.0030.08718.05
5.5.280.0070.04320.97
5.5.270.0030.08320.87
5.5.260.0100.06320.86
5.5.250.0070.04020.59
5.5.240.0200.07020.19

preferences:
142.77 ms | 1394 KiB | 7 Q