3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Filter { abstract public static function check($value, array $options = array()); } final class IntFilter extends Filter { public static function check($value, array $options = array()) { return $value; } } final class StringFilter extends Filter { public static function check($value, array $options = array()) { $length = mb_strlen($value, '8bit'); // Empty if (false === ($options['empty'] ?? true)) { if (0 === $length) { throw new LengthException('chaine vide !'); } } // Min & max length if ($options['max']) { $maxLength = IntFilter::check($options['max'], ['min' => 1]); if ($length > $maxLength) { throw new LengthException('trop long !'); } } if ($options['min']) { $minLength = IntFilter::check($options['min'], ['min' => 1]); if ($length > $minLength) { throw new LengthException('trop court !'); } } return $value; } } var_dump(StringFilter::check('test '));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key "max" in /in/92ZU2 on line 31 Warning: Undefined array key "min" in /in/92ZU2 on line 39 string(8) "test "
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key "max" in /in/92ZU2 on line 31 Warning: Undefined array key "min" in /in/92ZU2 on line 39 string(8) "test "
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: Undefined index: max in /in/92ZU2 on line 31 Notice: Undefined index: min in /in/92ZU2 on line 39 string(8) "test "
Output for 7.3.32 - 7.3.33, 7.4.26
string(8) "test "
Output for 5.6.38
Strict Standards: Static function Filter::check() should not be abstract in /in/92ZU2 on line 5 Parse error: syntax error, unexpected '?' in /in/92ZU2 on line 24
Process exited with code 255.

preferences:
165.43 ms | 401 KiB | 217 Q