3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Checks whether a string is valid json. * * @param string $string * @return boolean */ function json_is($string) { try { // try to decode string json_decode($string); } catch (ErrorException $e) { // exception has been caught which means argument wasn't a string and thus is definitely no json. return FALSE; } // check if error occured return (json_last_error() == JSON_ERROR_NONE); } // Make sure the string is not empty and is, in fact, a string. An empty string is not valid JSON. function is_json($string) { return !empty($string) && is_string($string) && is_array(json_decode($string, true)) && json_last_error() == 0; } //I think in PHP it's more important to determine if the JSON object even has data, because to use the data you will need to call json_encode() //or json_decode(). I suggest denying empty JSON objects so you aren't unnecessarily running encodes and decodes on empty data. function has_json_data($string) { $array = json_decode($string, true); return !empty($string) && is_string($string) && is_array($array) && !empty($array) && json_last_error() == 0; } function isJson($string, $assoc = false) { var_dump(json_decode($string)); json_decode($string, $assoc); if(!empty($string) && is_string($string)) { json_decode($string, $assoc); return (json_last_error() == JSON_ERROR_NONE); // return json_decode($str) != null; } return false; } $a=['arraiii'=>['dentro'=>234]]; $b=json_encode($a); $c='{}'; var_dump(isJson($c));

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.3.60.0070.00718.55
8.3.50.0100.01021.14
8.3.40.0110.00418.63
8.3.30.0180.00020.35
8.3.20.0040.00420.30
8.3.10.0040.00422.09
8.3.00.0040.00422.34
8.2.180.0000.01816.38
8.2.170.0000.01422.96
8.2.160.0030.01022.08
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0050.00326.16
8.2.120.0050.00320.80
8.2.110.0090.00022.11
8.2.100.0080.00317.91
8.2.90.0050.00319.19
8.2.80.0050.00319.38
8.2.70.0050.00317.75
8.2.60.0000.00818.04
8.2.50.0040.00418.07
8.2.40.0040.00418.16
8.2.30.0040.00419.53
8.2.20.0070.00017.67
8.2.10.0040.00417.68
8.2.00.0030.00517.85
8.1.280.0040.01125.92
8.1.270.0050.00323.99
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0090.00023.92
8.1.230.0080.00318.94
8.1.220.0050.00317.80
8.1.210.0000.00918.77
8.1.200.0060.00617.35
8.1.190.0030.00517.43
8.1.180.0060.00318.10
8.1.170.0080.00018.59
8.1.160.0040.00418.93
8.1.150.0060.00318.68
8.1.140.0040.00417.52
8.1.130.0040.00417.94
8.1.120.0040.00317.41
8.1.110.0040.00417.49
8.1.100.0000.00717.50
8.1.90.0040.00417.40
8.1.80.0070.00017.57
8.1.70.0040.00417.45
8.1.60.0060.00317.61
8.1.50.0040.00417.50
8.1.40.0000.00717.51
8.1.30.0040.00417.65
8.1.20.0040.00417.64
8.1.10.0000.00717.43
8.1.00.0060.00617.32
8.0.300.0060.00318.77
8.0.290.0040.00417.18
8.0.280.0000.00718.49
8.0.270.0040.00417.22
8.0.260.0000.00716.82
8.0.250.0070.00016.88
8.0.240.0040.00417.00
8.0.230.0040.00416.93
8.0.220.0000.00716.96
8.0.210.0000.00716.96
8.0.200.0000.00616.91
8.0.190.0060.00316.97
8.0.180.0040.00416.83
8.0.170.0040.00416.86
8.0.160.0080.00016.89
8.0.150.0050.00516.90
8.0.140.0030.00316.91
8.0.130.0050.00013.30
8.0.120.0040.00416.86
8.0.110.0000.00716.89
8.0.100.0040.00417.04
8.0.90.0040.00416.91
8.0.80.0060.00916.90
8.0.70.0000.00816.93
8.0.60.0000.00716.82
8.0.50.0000.00716.88
8.0.30.0100.01117.13
8.0.20.0110.00917.40
8.0.10.0070.00017.04
8.0.00.0080.01216.66
7.4.330.0030.00315.00
7.4.320.0030.00616.49
7.4.300.0040.00416.60
7.4.290.0000.00716.57
7.4.280.0000.00616.54
7.4.270.0000.00716.63
7.4.260.0050.00013.45
7.4.250.0040.00416.62
7.4.240.0020.00516.56
7.4.230.0030.00516.67
7.4.220.0060.01316.74
7.4.210.0100.00516.64
7.4.200.0030.00316.71
7.4.190.0030.00316.73
7.4.160.0120.00316.35
7.4.150.0040.01417.40
7.4.140.0080.01117.86
7.4.130.0090.00916.53
7.4.120.0100.00716.44
7.4.110.0120.00416.64
7.4.100.0120.01316.68
7.4.90.0140.00716.60
7.4.80.0100.01019.39
7.4.70.0030.01716.46
7.4.60.0060.01116.57
7.4.50.0080.00016.64
7.4.40.0100.00322.77
7.4.30.0060.01216.32
7.4.00.0070.01015.15
7.3.330.0000.00613.24
7.3.320.0060.00013.07
7.3.310.0040.00416.14
7.3.300.0000.00716.27
7.3.290.0050.00816.22
7.3.280.0090.00916.27
7.3.270.0090.00917.40
7.3.260.0000.02016.48
7.3.250.0060.01116.44
7.3.240.0060.00916.33
7.3.230.0050.01116.39
7.3.210.0070.01016.34
7.3.200.0100.00919.39
7.3.190.0140.00616.20
7.3.180.0030.01316.69
7.3.170.0090.00616.50
7.3.160.0150.00416.29
7.3.120.0070.00714.87
7.3.110.0000.01714.96
7.3.100.0060.00914.77
7.3.90.0070.00715.01
7.3.80.0070.00714.93
7.3.70.0030.01014.82
7.3.60.0100.00314.82
7.3.50.0110.00714.84
7.3.40.0060.00914.82
7.3.30.0060.00614.72
7.3.20.0090.00616.39
7.3.10.0130.00316.31
7.3.00.0060.00616.59
7.2.330.0100.00716.73
7.2.320.0090.01216.76
7.2.310.0100.00716.80
7.2.300.0060.00916.60
7.2.290.0060.01316.72
7.2.240.0000.01315.00
7.2.230.0100.00715.18
7.2.220.0070.01114.79
7.2.210.0060.00614.97
7.2.200.0040.01515.18
7.2.190.0070.01114.87
7.2.180.0040.00715.10
7.2.170.0040.01115.14
7.2.160.0040.01114.94
7.2.150.0100.00717.02
7.2.140.0040.00716.96
7.2.130.0110.00416.89
7.2.120.0060.00916.73
7.2.110.0130.00316.89
7.2.100.0130.00016.64
7.2.90.0060.00816.73
7.2.80.0070.00716.88
7.2.70.0030.01116.79
7.2.60.0030.01016.75
7.2.50.0000.01016.68
7.2.40.0060.00916.75
7.2.30.0040.01416.95
7.2.20.0030.00716.57
7.2.10.0030.01316.73
7.2.00.0050.00618.04
7.1.330.0080.00815.82
7.1.320.0070.01015.64
7.1.310.0070.00715.85
7.1.300.0040.00815.70
7.1.290.0150.00015.68
7.1.280.0040.01115.55
7.1.270.0090.00315.45
7.1.260.0040.01415.87
7.1.250.0000.01115.89
7.1.100.0070.01417.92
7.1.70.0030.00316.88
7.1.60.0040.00717.06
7.1.50.0040.01316.60
7.1.00.0030.05322.41
7.0.200.0000.00716.94
7.0.140.0030.07322.10
7.0.90.0600.05019.93
7.0.80.0430.05320.01
7.0.70.0600.07019.96
7.0.60.0470.05020.02
7.0.50.0470.07320.41
7.0.40.0170.03720.13
7.0.30.0070.08719.96
7.0.20.0130.07720.17
7.0.10.0070.08720.03
7.0.00.0070.04020.14
5.6.280.0030.07321.08
5.6.240.0030.05320.71
5.6.230.0000.04720.64
5.6.220.0130.07320.63
5.6.210.0030.09020.63
5.6.200.0100.08320.97
5.6.190.0100.07021.18
5.6.180.0130.08021.07
5.6.170.0130.07721.08
5.6.160.0100.03721.00
5.6.150.0100.03721.18
5.6.140.0100.08721.12
5.6.130.0070.09021.05
5.6.120.0070.06321.02
5.6.110.0100.05320.99
5.6.100.0070.04321.11
5.6.90.0070.07021.11
5.6.80.0070.06320.33
5.6.70.0100.06720.34
5.6.60.0070.08020.27
5.6.50.0130.07720.50
5.6.40.0070.06020.38
5.6.30.0030.05020.30
5.6.20.0030.04320.38
5.6.10.0100.08020.49
5.6.00.0070.07720.37
5.5.380.0070.08020.46
5.5.370.0070.05020.55
5.5.360.0100.05320.36
5.5.350.0030.04720.45
5.5.340.0070.08720.90
5.5.330.0100.07720.82
5.5.320.0170.07320.94
5.5.310.0130.06020.73
5.5.300.0100.06020.74
5.5.290.0000.08720.90
5.5.280.0030.09320.77
5.5.270.0030.05020.92
5.5.260.0070.05720.76
5.5.250.0100.07320.74
5.5.240.0200.03720.26
5.5.230.0070.07020.19
5.5.220.0070.07720.14
5.5.210.0170.05320.21
5.5.200.0130.06720.16
5.5.190.0070.08020.16
5.5.180.0100.06720.22
5.5.160.0130.07720.14
5.5.150.0100.08020.00
5.5.140.0200.07720.13
5.5.130.0100.08020.11
5.5.120.0070.07020.19
5.5.110.0230.03720.14
5.5.100.0100.04720.06
5.5.90.0030.05020.18
5.5.80.0030.07020.10
5.5.70.0030.08020.16
5.5.60.0070.08020.06
5.5.50.0070.08320.06
5.5.40.0130.06320.16
5.5.30.0100.08320.05
5.5.20.0130.04320.00
5.5.10.0100.07319.97
5.5.00.0070.07320.04
5.4.450.0130.07319.46
5.4.440.0130.07719.51
5.4.430.0030.05019.50
5.4.420.0100.05719.55
5.4.410.0170.06319.24
5.4.400.0030.04719.14
5.4.390.0000.08719.18
5.4.380.0170.06318.88
5.4.370.0130.06718.89
5.4.360.0030.08319.02
5.4.350.0070.07019.18
5.4.340.0030.04318.85
5.4.320.0100.07018.85
5.4.310.0030.05719.05
5.4.300.0170.07019.19
5.4.290.0070.05019.07
5.4.280.0030.08719.20
5.4.270.0070.05719.02
5.4.260.0100.04318.88
5.4.250.0030.07719.17
5.4.240.0070.07319.11
5.4.230.0200.06319.09
5.4.220.0100.07319.24
5.4.210.0100.06319.15
5.4.200.0130.07018.90
5.4.190.0070.07019.11
5.4.180.0070.05719.02
5.4.170.0070.05319.11
5.4.160.0130.03019.11
5.4.150.0030.05319.07
5.4.140.0030.07716.42
5.4.130.0100.06716.19
5.4.120.0000.07316.44
5.4.110.0100.07016.32
5.4.100.0170.04716.52
5.4.90.0030.07316.45
5.4.80.0100.07016.38
5.4.70.0100.05716.54
5.4.60.0100.07316.45
5.4.50.0100.06716.48
5.4.40.0070.05016.53
5.4.30.0030.07716.41
5.4.20.0030.06016.27
5.4.10.0030.05716.47
5.4.00.0030.03715.82
5.3.290.0000.08014.74
5.3.280.0070.07714.68
5.3.270.0000.08714.63
5.3.260.0030.05314.69
5.3.250.0070.07014.75
5.3.240.0030.07314.71
5.3.230.0030.08314.64
5.3.220.0100.06714.63
5.3.210.0130.07014.50
5.3.200.0030.05714.53
5.3.190.0100.05714.70
5.3.180.0030.05014.58
5.3.170.0130.05714.58
5.3.160.0030.08014.69
5.3.150.0100.07014.47
5.3.140.0070.07314.57
5.3.130.0000.08014.54
5.3.120.0030.08014.65
5.3.110.0100.07314.59
5.3.100.0030.08014.05
5.3.90.0100.06014.04
5.3.80.0170.06013.98
5.3.70.0070.07314.17
5.3.60.0030.05314.12
5.3.50.0100.07013.98
5.3.40.0170.07014.06
5.3.30.0030.08013.81
5.3.20.0030.05313.84
5.3.10.0000.06313.68
5.3.00.0100.05713.67
5.2.170.0070.06011.02
5.2.160.0030.06011.15
5.2.150.0030.06311.09
5.2.140.0030.06011.29
5.2.130.0000.05011.03
5.2.120.0100.04711.25
5.2.110.0000.06711.24
5.2.100.0030.05711.01
5.2.90.0030.04311.13
5.2.80.0070.03711.13
5.2.70.0030.05011.16
5.2.60.0070.05711.21
5.2.50.0030.06311.18
5.2.40.0100.05710.95
5.2.30.0100.06011.00
5.2.20.0070.06310.83
5.2.10.0130.04711.01
5.2.00.0030.03710.72
5.1.60.0070.05310.00
5.1.50.0000.05310.13
5.1.40.0100.0479.97
5.1.30.0070.05310.45
5.1.20.0030.06010.37
5.1.10.0170.04010.16
5.1.00.0030.04310.09
5.0.50.0070.0478.40
5.0.40.0070.0438.54
5.0.30.0030.0638.23
5.0.20.0070.0378.30
5.0.10.0030.0378.24
5.0.00.0030.0638.18
4.4.90.0070.0337.76
4.4.80.0030.0337.76
4.4.70.0070.0307.76
4.4.60.0070.0307.76
4.4.50.0000.0377.76
4.4.40.0000.0507.76
4.4.30.0000.0307.76
4.4.20.0030.0377.76
4.4.10.0000.0237.76
4.4.00.0000.0437.76
4.3.110.0070.0277.76
4.3.100.0070.0307.76
4.3.90.0030.0337.76
4.3.80.0030.0537.76
4.3.70.0030.0307.76
4.3.60.0000.0377.76
4.3.50.0030.0337.76
4.3.40.0000.0507.76
4.3.30.0000.0377.76
4.3.20.0030.0337.76
4.3.10.0030.0337.76
4.3.00.0030.0277.76

preferences:
37.42 ms | 401 KiB | 5 Q