3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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; } $str = 's:4:"test"xxx'; if (is_serialized($str, false)) echo 'fuck'; else echo 'haha'; if (is_serialized($str)) echo 'haha'; else echo 'fuck';
Output for 5.4.0 - 5.4.34
Parse error: syntax error, unexpected '(is_serialized' (T_STRING), expecting '(' in /in/eA2AE on line 65
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING, expecting '(' in /in/eA2AE on line 65
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING, expecting '(' in /in/eA2AE on line 65
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'('' in /in/eA2AE on line 65
Process exited with code 255.

preferences:
231 ms | 1395 KiB | 124 Q