3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function wd_check_serialization( $string, &$errmsg ) { $str = 's'; $array = 'a'; $integer = 'i'; $any = '[^}]*?'; $count = '\d+'; $content = '"(?:\\\";|.)*?";'; $open_tag = '\{'; $close_tag = '\}'; $parameter = "($str|$array|$integer|$any):($count)" . "(?:[:]($open_tag|$content)|[;])"; $preg = "/$parameter|($close_tag)/"; if( !preg_match_all( $preg, $string, $matches ) ) { $errmsg = 'not a serialized string'; return false; } $open_arrays = 0; foreach( $matches[1] AS $key => $value ) { if( !empty( $value ) && ( $value != $array xor $value != $str xor $value != $integer ) ) { $errmsg = 'undefined datatype'; return false; } if( $value == $array ) { $open_arrays++; if( $matches[3][$key] != '{' ) { $errmsg = 'open tag expected'; return false; } } if( $value == '' ) { if( $matches[4][$key] != '}' ) { $errmsg = 'close tag expected'; return false; } $open_arrays--; } if( $value == $str ) { $aVar = ltrim( $matches[3][$key], '"' ); $aVar = rtrim( $aVar, '";' ); if( strlen( $aVar ) != $matches[2][$key] ) { $errmsg = 'stringlen for string not match'; return false; } } if( $value == $integer ) { if( !empty( $matches[3][$key] ) ) { $errmsg = 'unexpected data'; return false; } if( !is_integer( (int)$matches[2][$key] ) ) { $errmsg = 'integer expected'; return false; } } } if( $open_arrays != 0 ) { $errmsg = 'wrong setted arrays'; return false; } return true; } var_dump(wd_check_serialization('a:1:{i:0;a:10:{s:2:"id";s:3:"191";s:12:"variation_id";s:3:"193";s:4:"name";s:42:"Serviette Havana Club mit Gastro-Logodruck";s:3:"qty";s:1:"1";s:9:"item_meta";a:2:{i:0;a:2:{s:9:"meta_name";s:6:"pa_vpe";s:10:"meta_value";s:6:"18-900";}i:1;a:2:{s:9:"meta_name";s:12:"pa_erstdruck";s:10:"meta_value";s:4:"nein";}}s:13:"line_subtotal";s:3:"360";s:17:"line_subtotal_tax";s:4:"68.4";s:10:"line_total";s:3:"360";s:8:"line_tax";s:4:"68.4";s:9:"tax_class";s:19:"gesetzliche-mwst-19";}}"'));
Output for 7.1.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function wd_check_serialization(), 1 passed in /in/ZHtkY on line 81 and exactly 2 expected in /in/ZHtkY:4 Stack trace: #0 /in/ZHtkY(81): wd_check_serialization('a:1:{i:0;a:10:{...') #1 {main} thrown in /in/ZHtkY on line 4
Process exited with code 255.
Output for 5.1.0 - 7.0.14
Warning: Missing argument 2 for wd_check_serialization(), called in /in/ZHtkY on line 81 and defined in /in/ZHtkY on line 4 bool(true)
Output for 4.3.0 - 5.0.5
Warning: Missing argument 2 for wd_check_serialization() in /in/ZHtkY on line 4 bool(true)