3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Php8CompatUtils { public static function eq($a, $b): bool { // If both $a and $b are of type strings, compare them as strings if (is_string($a) && is_string($b)) { return $a == $b; // may not be === because php says '42' equals '042' true yet '42' === '042' is false. } // If both $a and $b are numeric strings, compare them as numbers if (is_numeric($a) && is_numeric($b)) { return $a == $b; } // If $a is an empty string and $b is 0, or vice versa, return true if (($a === '' && $b === 0) || ($a === 0 && $b === '')) { return true; } // If $a is a non-numeric string and $b is 0, or vice versa, return true if ((is_string($a) && ($a !== '') && ($b === 0)) || (($a === 0) && is_string($b) && ($b !== ''))) { return true; } // special case '123abc' == 123 .. php 7 casts 123abc to 123, then 123 == 123 results in true. lets mimic that. if ((is_string($a) && ($a !== '') && (is_numeric($b)) && ((bool)$b))) { $number = filter_var($a, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); //"-234.56xyz" return $number == $b; } if (is_numeric($a) && ((bool)$a) && is_string($b) && ($b !== '')) { $number = filter_var($b, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); //"-234.56xyz" return $a == $number; } // If $a is a number and $b is a non-numeric string, cast $a to string and compare if (is_numeric($a) && is_string($b)) { return strval($a) == $b; } // If $b is a number and $a is a non-numeric string, cast $b to string and compare if (is_string($a) && is_numeric($b)) { return $a == strval($b); } if (is_array($a) || is_array($b)) { return static::standardArrayCompare($a, $b) == 0; } // If $a and $b are both non-numeric strings, compare them directly, we should return true if they are the same return $a == $b; } public static function gt($a, $b): bool { if (static::eq($a, $b)) { return false; } if (is_array($a) || is_array($b)) { return static::standardArrayCompare($a, $b) < 0; } return $a > $b; } public static function lt($a, $b): bool { if (static::eq($a, $b)) { return false; } if (is_array($a) || is_array($b)) { return static::standardArrayCompare($a, $b) > 0; } return $a < $b; } public static function gte($a, $b): bool { if (is_array($a) || is_array($b)) { return static::standardArrayCompare($a, $b) >= 0; } return static::eq($a, $b) || ($a > $b); } public static function lte($a, $b): bool { if (is_array($a) || is_array($b)) { return static::standardArrayCompare($a, $b) <= 0; } return static::eq($a, $b) || ($a < $b); } private static function standardArrayCompare($op1, $op2) { if (count($op1) < count($op2)) { return -1; // $op1 < $op2 } elseif (count($op1) > count($op2)) { return 1; // $op1 > $op2 } foreach ($op1 as $key => $val) { if (!array_key_exists($key, $op2)) { return 1; } elseif (static::lt($val, $op2[$key])) { return -1; } elseif (static::gt($val, $op2[$key])) { return 1; } } return 0; // $op1 == $op2 } } $a = [0 => '']; $b = [0 => 0]; var_dump(Php8CompatUtils::eq($a, $b)); var_dump($a == $b);

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)
8.4.30.0090.01018.86
8.4.20.0420.00717.43
8.4.10.0370.00917.46
8.3.160.0140.00716.42
8.3.150.0410.00516.53
8.3.140.0400.00316.62
8.3.130.0360.00616.47
8.3.120.0370.00516.50
8.3.110.0210.01416.54
8.3.100.0360.00516.39
8.3.90.0370.00916.67
8.3.80.0370.00716.52
8.3.70.0320.00816.52
8.3.60.0320.00816.61
8.3.50.0280.00516.53
8.3.40.0220.00717.63
8.3.30.0260.01117.46
8.3.20.0260.01017.44
8.3.10.0240.01117.56
8.3.00.0220.00617.51
8.2.270.0310.00516.25
8.2.260.0430.00616.49
8.2.250.0290.01316.73
8.2.240.0220.01716.41
8.2.230.0270.01216.33
8.2.220.0250.00916.51
8.2.210.0250.01116.29
8.2.200.0310.00616.64
8.2.190.0330.00516.34
8.2.180.0240.01516.51
8.2.170.0260.01017.73
8.2.160.0250.00617.70
8.2.150.0300.01017.53
8.2.140.0360.00517.40
8.2.130.0340.00617.53
8.2.120.0310.01117.63
8.2.110.0350.00817.53
8.2.100.0300.00817.56
8.2.90.0280.01117.69
8.2.80.0320.00817.27
8.2.70.0320.00617.36
8.2.60.0190.01117.58
8.2.50.0370.00317.49
8.2.40.0310.00517.60
8.2.30.0310.00817.53
8.2.20.0250.01117.38
8.2.10.0250.01017.65
8.2.00.0280.00717.57

preferences:
28.03 ms | 403 KiB | 5 Q