3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface PolicyRule { public function isSatisfiedBy(); } abstract class EnforcedRule implements PolicyRule { const TYPE_NO = 'No'; const TYPE_YES = 'Yes'; protected $enforcementType; protected function isEnforced() { return ($this->enforcementType == self::TYPE_YES); } protected function guardEnforcementType(string $aType) { if (! in_array($aType, [self::TYPE_NO, self::TYPE_YES])) { 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) { 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) { $this->minimumCount = $aMinimumCount; } } class SpecialCharacterRule extends MinimumCharacterCountRule { protected $regexPattern = '/[~`#\$%\^&\*\(\)\-_\+\|,\.<>]/'; public function __construct(int $aMinimumCount = self::DEFAULT_MINIMUM) { $this->minimumCount = $aMinimumCount; } } $numeric = new NumericRule(); var_dump($numeric->isSatisfiedBy("for5"));
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Declaration of MinimumCharacterCountRule::isSatisfiedBy(string $aValue) must be compatible with PolicyRule::isSatisfiedBy() in /in/R0CUu on line 36
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Fatal error: Declaration of MinimumCharacterCountRule::isSatisfiedBy(string $aValue) must be compatible with PolicyRule::isSatisfiedBy() in /in/R0CUu on line 28
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Fatal error: Declaration of MinimumCharacterCountRule::isSatisfiedBy() must be compatible with PolicyRule::isSatisfiedBy() in /in/R0CUu on line 29
Process exited with code 255.
Output for 5.5.24 - 5.5.35
Fatal error: Default value for parameters with a class type hint can only be NULL in /in/R0CUu on line 53
Process exited with code 255.

preferences:
196.84 ms | 401 KiB | 213 Q