3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Check value to find if it was serialized. * * If $data is not an string, then returned value will always be false. * Serialized data is always a string. * * @since 2.0.5 * * @param string $data Value to check to see if was serialized. * @param bool $strict Optional. Whether to be strict about the end of the string. Default true. * @return bool False if not serialized and true if it was. */ function is_serialized( $data, $strict = true ) { // if it isn't a string, it isn't serialized. if ( ! is_string( $data ) ) { return false; } $data = trim( $data ); if ( 'N;' == $data ) { return true; } if ( strlen( $data ) < 4 ) { return false; } if ( ':' !== $data[1] ) { return false; } if ( $strict ) { $lastc = substr( $data, -1 ); if ( ';' !== $lastc && '}' !== $lastc ) { return false; } } else { $semicolon = strpos( $data, ';' ); $brace = strpos( $data, '}' ); // Either ; or } must exist. if ( false === $semicolon && false === $brace ) return false; // But neither must be in the first X characters. if ( false !== $semicolon && $semicolon < 3 ) return false; if ( false !== $brace && $brace < 4 ) return false; } $token = $data[0]; switch ( $token ) { case 's' : if ( $strict ) { if ( '"' !== substr( $data, -2, 1 ) ) { return false; } } elseif ( false === strpos( $data, '"' ) ) { return false; } // or else fall through case 'a' : case 'O' : return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); case 'b' : case 'i' : case 'd' : $end = $strict ? '$' : ''; return (bool) preg_match( "/^{$token}:[0-9.E-]+;$end/", $data ); } return false; } /** * Check whether serialized data is of string type. * * @since 2.0.5 * * @param string $data Serialized data. * @return bool False if not a serialized string, true if it is. */ function is_serialized_string( $data ) { // if it isn't a string, it isn't a serialized string. if ( ! is_string( $data ) ) { return false; } $data = trim( $data ); if ( strlen( $data ) < 4 ) { return false; } elseif ( ':' !== $data[1] ) { return false; } elseif ( ';' !== substr( $data, -1 ) ) { return false; } elseif ( $data[0] !== 's' ) { return false; } elseif ( '"' !== substr( $data, -2, 1 ) ) { return false; } else { return true; } } var_dump( is_serialized( serialize(NULL) ) ); // true var_dump( is_serialized_string( serialize(NULL) ) ); // false var_dump( is_serialized( serialize(array(1,2,3)) ) ); // true var_dump( is_serialized_string( serialize(array(1,2,3)) ) ); // false var_dump( is_serialized( serialize("hello") ) ); // true var_dump( is_serialized_string( serialize("hello") ) ); // false

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.120.0090.01220.72
8.4.110.0110.00922.61
8.4.100.0130.00818.84
8.4.90.0040.00418.93
8.4.80.0120.00820.45
8.4.70.0130.00620.80
8.4.60.0070.00518.84
8.4.50.0130.00717.80
8.4.40.0100.01017.79
8.4.30.0160.00318.00
8.4.20.0140.00019.77
8.4.10.0060.00618.09
8.3.250.0090.00918.86
8.3.240.0090.00916.67
8.3.230.0120.00516.95
8.3.220.0120.00818.86
8.3.210.0040.00418.75
8.3.200.0030.00616.88
8.3.190.0020.00617.07
8.3.180.0060.00317.28
8.3.170.0000.01420.67
8.3.160.0130.00617.30
8.3.150.0120.00617.39
8.3.140.0080.00016.93
8.3.130.0070.00316.91
8.3.120.0090.00020.85
8.3.110.0090.00020.94
8.3.100.0100.01016.85
8.3.90.0100.01026.77
8.3.80.0070.00417.97
8.3.70.0080.00818.55
8.3.60.0130.01016.88
8.3.50.0120.00517.56
8.3.40.0000.01419.10
8.3.30.0060.00918.75
8.3.20.0110.00320.52
8.3.10.0040.00423.48
8.3.00.0050.00323.66
8.2.290.0090.00320.46
8.2.280.0090.01118.54
8.2.270.0090.00917.27
8.2.260.0030.00516.70
8.2.250.0030.00618.96
8.2.240.0060.00317.48
8.2.230.0070.00322.58
8.2.220.0000.00824.06
8.2.210.0080.00026.77
8.2.200.0110.00017.10
8.2.190.0180.00416.63
8.2.180.0040.01118.54
8.2.170.0150.00022.96
8.2.160.0070.01120.59
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.01522.22
8.2.120.0030.00526.35
8.2.110.0030.00622.30
8.2.100.0000.01218.09
8.2.90.0000.00817.88
8.2.80.0050.00319.09
8.2.70.0090.00018.00
8.2.60.0040.00418.05
8.2.50.0080.00018.07
8.2.40.0000.00818.23
8.2.30.0030.00518.22
8.2.20.0030.00518.09
8.2.10.0000.00718.27
8.2.00.0040.00418.21
8.1.330.0060.00221.84
8.1.320.0110.01116.29
8.1.310.0060.00316.80
8.1.300.0030.00620.05
8.1.290.0100.00030.84
8.1.280.0130.00625.92
8.1.270.0090.00022.20
8.1.260.0080.00026.35
8.1.250.0030.00728.09
8.1.240.0110.00019.19
8.1.230.0090.00318.02
8.1.220.0030.00617.77
8.1.210.0060.00318.77
8.1.200.0040.00417.60
8.1.190.0000.00817.48
8.1.180.0060.00318.10
8.1.170.0090.00018.71
8.1.160.0000.00718.99
8.1.150.0030.00520.68
8.1.140.0000.00917.79
8.1.130.0030.00319.03
8.1.120.0030.00917.71
8.1.110.0000.00817.68
8.1.100.0040.00417.59
8.1.90.0040.00417.61
8.1.80.0040.00417.54
8.1.70.0040.00417.68
8.1.60.0000.00817.81
8.1.50.0000.00817.75
8.1.40.0080.00017.75
8.1.30.0000.00817.93
8.1.20.0030.00517.75
8.1.10.0000.00817.84
8.1.00.0040.00417.66
8.0.300.0080.00018.77
8.0.290.0000.00816.88
8.0.280.0030.00318.54
8.0.270.0050.00317.09
8.0.260.0000.00816.93
8.0.250.0030.00317.17
8.0.240.0030.00617.16
8.0.230.0050.00317.23
8.0.220.0000.00717.13
8.0.210.0080.00017.13
8.0.200.0000.00717.18
8.0.190.0000.00817.13
8.0.180.0070.00017.02
8.0.170.0000.00717.11
8.0.160.0050.00317.10
8.0.150.0000.00817.01
8.0.140.0030.00617.06
8.0.130.0050.00013.53
8.0.120.0040.00416.96
8.0.110.0050.00217.04
8.0.100.0040.00417.02
8.0.90.0040.00417.14
8.0.80.0030.01217.15
8.0.70.0040.00416.88
8.0.60.0000.00717.05
8.0.50.0040.00417.07
8.0.30.0100.00817.39
8.0.20.0110.01017.47
8.0.10.0040.00417.22
8.0.00.0090.01016.82
7.4.330.0000.00616.91
7.4.320.0030.00316.88
7.4.300.0000.00616.91
7.4.290.0050.00316.87
7.4.280.0000.00816.86
7.4.270.0030.00316.78
7.4.260.0000.00716.72
7.4.250.0000.00816.86
7.4.240.0030.00316.78
7.4.230.0000.00716.70
7.4.220.0120.00916.95
7.4.210.0090.00616.80
7.4.200.0040.00416.98
7.4.160.0110.00716.82
7.4.150.0160.00417.40
7.4.140.0090.00917.86
7.4.130.0120.01216.98
7.4.120.0120.01116.83
7.4.110.0100.00716.80
7.4.100.0100.00716.86
7.4.90.0150.00316.82
7.4.80.0090.00919.39
7.4.70.0090.01016.86
7.4.60.0030.01316.58
7.4.50.0140.00416.73
7.4.40.0060.01016.74
7.4.30.0100.00716.69
7.4.10.0100.01015.36
7.4.00.0070.01115.20
7.3.330.0000.00613.54
7.3.320.0030.00313.55
7.3.310.0030.00316.46
7.3.300.0000.00716.58
7.3.290.0100.00816.57
7.3.280.0120.00616.58
7.3.270.0100.00717.40
7.3.260.0080.01116.75
7.3.250.0100.00816.74
7.3.240.0050.01316.62
7.3.230.0080.00816.84
7.3.210.0100.00816.60
7.3.200.0060.01516.65
7.3.190.0030.01616.68
7.3.180.0120.00916.81
7.3.170.0040.01216.54
7.3.160.0120.00916.54
7.3.130.0140.00415.19
7.3.120.0080.00815.15
7.3.110.0110.00715.20
7.3.100.0050.00714.94
7.3.90.0060.00815.11
7.3.80.0070.00815.19
7.3.70.0070.00615.01
7.3.60.0070.00615.05
7.3.50.0060.00815.05
7.3.40.0050.00915.18
7.3.30.0090.00715.12
7.3.20.0040.00916.82
7.3.10.0060.00517.03
7.3.00.0040.00716.74
7.2.330.0090.01217.11
7.2.320.0130.00616.88
7.2.310.0120.00616.96
7.2.300.0110.00616.78
7.2.290.0180.00316.98
7.2.260.0110.00815.11
7.2.250.0050.01415.29
7.2.240.0040.01215.27
7.2.230.0030.01315.22
7.2.220.0050.00615.26
7.2.210.0080.01115.37
7.2.200.0110.00315.35
7.2.190.0050.01015.38
7.2.180.0020.01215.20
7.2.170.0050.00715.15
7.2.160.0030.00715.49
7.2.150.0060.00916.99
7.2.140.0070.00317.13
7.2.130.0060.00317.18
7.2.120.0140.00017.04
7.2.110.0080.00417.10
7.2.100.0090.00016.88
7.2.90.0060.00317.02
7.2.80.0030.01017.00
7.2.70.0100.00317.27
7.2.60.0070.00816.88
7.2.50.0000.01417.02
7.2.40.0000.01417.30
7.2.30.0070.00716.82
7.2.20.0130.00017.27
7.2.10.0060.00916.97
7.2.00.0040.01417.06
7.1.330.0050.00915.93
7.1.320.0060.00615.85
7.1.310.0090.00716.12
7.1.300.0040.00815.89
7.1.290.0030.01015.99
7.1.280.0030.01116.08
7.1.270.0080.00815.92
7.1.260.0050.00516.02
7.1.250.0080.00415.85
7.1.240.0030.01316.14
7.1.230.0090.00616.09
7.1.220.0030.00615.78
7.1.210.0060.00616.05
7.1.200.0020.01115.93
7.1.190.0030.01015.87
7.1.180.0070.00716.16
7.1.170.0000.01416.02
7.1.160.0060.00616.14
7.1.150.0070.00715.91
7.1.140.0070.00715.82
7.1.130.0030.00615.82
7.1.120.0030.00915.80
7.1.110.0090.00617.37
7.1.100.0060.00917.00
7.1.90.0060.00917.04
7.1.80.0030.01217.19
7.1.70.0080.00916.57
7.1.60.0140.00625.75
7.1.50.0120.01225.46
7.1.40.0170.00825.40
7.1.30.0140.00725.29
7.1.20.0160.01025.34
7.1.10.0030.01416.41
7.1.00.0070.01116.42
7.0.330.0030.01315.49
7.0.320.0040.00715.63
7.0.310.0000.01115.64
7.0.300.0070.00415.52
7.0.290.0070.00715.52
7.0.280.0080.00415.38
7.0.270.0100.00315.44
7.0.260.0000.00815.64
7.0.250.0050.00816.88
7.0.240.0070.00916.88
7.0.230.0060.01016.90
7.0.220.0070.00716.82
7.0.210.0090.00816.08
7.0.200.0090.00716.33
7.0.190.0110.00616.29
7.0.180.0030.01415.87
7.0.170.0080.00815.91
7.0.160.0030.01116.07
7.0.150.0050.01016.02
7.0.140.0070.01015.89
7.0.130.0060.00816.09
7.0.120.0040.01116.12
7.0.110.0010.01516.29
7.0.100.0060.01216.19
7.0.90.0070.00816.17
7.0.80.0070.01016.18
7.0.70.0070.00816.12
7.0.60.0060.01016.01
7.0.50.0030.01315.97
7.0.40.0060.00915.15
7.0.30.0040.00715.28
7.0.20.0080.01015.16
7.0.10.0080.00915.24
7.0.00.0210.01014.28
5.6.400.0040.00814.77
5.6.390.0000.00914.05
5.6.380.0000.01214.74
5.6.370.0030.01014.74
5.6.360.0060.00614.70
5.6.350.0070.00414.77
5.6.340.0000.01514.76
5.6.330.0040.01114.42
5.6.320.0120.00314.64
5.6.310.0030.00714.46
5.6.300.0060.01014.75
5.6.290.0040.00714.63
5.6.280.0070.00714.68
5.6.270.0060.00314.25
5.6.260.0070.00714.72
5.6.250.0040.01514.19
5.6.240.0110.00314.49
5.6.230.0000.01814.31
5.6.220.0040.01114.35
5.6.210.0040.01114.67
5.6.200.0070.00714.35
5.6.190.0030.00714.42
5.6.180.0110.00314.51
5.6.170.0100.00314.34
5.6.160.0060.00914.60
5.6.150.0000.01714.66
5.6.140.0000.00914.61
5.6.130.0000.00914.50
5.6.120.0120.00414.65
5.6.110.0130.00014.25
5.6.100.0040.00814.32
5.6.90.0030.00614.26
5.6.80.0100.00314.05
5.6.70.0000.01714.61
5.6.60.0090.00914.68
5.6.50.0070.00714.45
5.6.40.0040.00714.51
5.6.30.0140.00414.37
5.6.20.0030.01414.36
5.6.10.0030.01214.10
5.6.00.0030.01014.30

preferences:
29.74 ms | 403 KiB | 5 Q