3v4l.org

run code in 300+ PHP versions simultaneously
<?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:"390";s:12:"variation_id";s:3:"393";s:4:"name";s:38:"Serviette Absolut mit Gastro-Logodruck";s:3:"qty";s:1:"1";s:9:"item_meta";a:3:{i:0;a:2:{s:9:"meta_name";s:51:"Geben Sie bitte hier die gewünschte Zusatzfarbe an";s:10:"meta_value";s:12:"schwarzgold";}i:1;a:2:{s:9:"meta_name";s:6:"pa_vpe";s:10:"meta_value";s:6:"18-900";}i:2;a:2:{s:9:"meta_name";s:12:"pa_erstdruck";s:10:"meta_value";s:2:"ja";}}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";}}'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DI4Y5
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'wd_check_serialization'
          2        SEND_VAL                                                 'a%3A1%3A%7Bi%3A0%3Ba%3A10%3A%7Bs%3A2%3A%22id%22%3Bs%3A3%3A%22390%22%3Bs%3A12%3A%22variation_id%22%3Bs%3A3%3A%22393%22%3Bs%3A4%3A%22name%22%3Bs%3A38%3A%22Serviette+Absolut+mit+Gastro-Logodruck%22%3Bs%3A3%3A%22qty%22%3Bs%3A1%3A%221%22%3Bs%3A9%3A%22item_meta%22%3Ba%3A3%3A%7Bi%3A0%3Ba%3A2%3A%7Bs%3A9%3A%22meta_name%22%3Bs%3A51%3A%22Geben+Sie+bitte+hier+die+gew%C3%BCnschte+Zusatzfarbe+an%22%3Bs%3A10%3A%22meta_value%22%3Bs%3A12%3A%22schwarzgold%22%3B%7Di%3A1%3Ba%3A2%3A%7Bs%3A9%3A%22meta_name%22%3Bs%3A6%3A%22pa_vpe%22%3Bs%3A10%3A%22meta_value%22%3Bs%3A6%3A%2218-900%22%3B%7Di%3A2%3Ba%3A2%3A%7Bs%3A9%3A%22meta_name%22%3Bs%3A12%3A%22pa_erstdruck%22%3Bs%3A10%3A%22meta_value%22%3Bs%3A2%3A%22ja%22%3B%7D%7Ds%3A13%3A%22line_subtotal%22%3Bs%3A3%3A%22360%22%3Bs%3A17%3A%22line_subtotal_tax%22%3Bs%3A4%3A%2268.4%22%3Bs%3A10%3A%22line_total%22%3Bs%3A3%3A%22360%22%3Bs%3A8%3A%22line_tax%22%3Bs%3A4%3A%2268.4%22%3Bs%3A9%3A%22tax_class%22%3Bs%3A19%3A%22gesetzliche-mwst-19%22%3B%7D%7D'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function wd_check_serialization:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 77) Position 1 = 46, Position 2 = 122
Branch analysis from position: 46
2 jumps found. (Code = 78) Position 1 = 47, Position 2 = 122
Branch analysis from position: 47
2 jumps found. (Code = 46) Position 1 = 51, Position 2 = 57
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 61
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 71
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 71
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 81
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 80
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 103
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 100, Position 2 = 103
Branch analysis from position: 100
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 103
2 jumps found. (Code = 43) Position 1 = 105, Position 2 = 121
Branch analysis from position: 105
2 jumps found. (Code = 43) Position 1 = 109, Position 2 = 112
Branch analysis from position: 109
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 118, Position 2 = 121
Branch analysis from position: 118
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 121
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 121
Branch analysis from position: 103
Branch analysis from position: 81
Branch analysis from position: 71
Branch analysis from position: 57
Branch analysis from position: 122
2 jumps found. (Code = 43) Position 1 = 125, Position 2 = 127
Branch analysis from position: 125
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 127
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 122
filename:       /in/DI4Y5
function name:  wd_check_serialization
number of ops:  129
compiled vars:  !0 = $string, !1 = $errmsg, !2 = $str, !3 = $array, !4 = $integer, !5 = $any, !6 = $count, !7 = $content, !8 = $open_tag, !9 = $close_tag, !10 = $parameter, !11 = $preg, !12 = $matches, !13 = $open_arrays, !14 = $value, !15 = $key, !16 = $aVar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        ASSIGN                                                   !2, 's'
    8     3        ASSIGN                                                   !3, 'a'
    9     4        ASSIGN                                                   !4, 'i'
   10     5        ASSIGN                                                   !5, '%5B%5E%7D%5D%2A%3F'
   11     6        ASSIGN                                                   !6, '%5Cd%2B'
   12     7        ASSIGN                                                   !7, '%22%28%3F%3A%5C%5C%22%3B%7C.%29%2A%3F%22%3B'
   13     8        ASSIGN                                                   !8, '%5C%7B'
   14     9        ASSIGN                                                   !9, '%5C%7D'
   15    10        ROPE_INIT                                    11  ~26     '%28'
         11        ROPE_ADD                                      1  ~26     ~26, !2
         12        ROPE_ADD                                      2  ~26     ~26, '%7C'
         13        ROPE_ADD                                      3  ~26     ~26, !3
         14        ROPE_ADD                                      4  ~26     ~26, '%7C'
         15        ROPE_ADD                                      5  ~26     ~26, !4
         16        ROPE_ADD                                      6  ~26     ~26, '%7C'
         17        ROPE_ADD                                      7  ~26     ~26, !5
         18        ROPE_ADD                                      8  ~26     ~26, '%29%3A%28'
         19        ROPE_ADD                                      9  ~26     ~26, !6
         20        ROPE_END                                     10  ~25     ~26, '%29'
         21        ROPE_INIT                                     5  ~33     '%28%3F%3A%5B%3A%5D%28'
         22        ROPE_ADD                                      1  ~33     ~33, !8
         23        ROPE_ADD                                      2  ~33     ~33, '%7C'
         24        ROPE_ADD                                      3  ~33     ~33, !7
         25        ROPE_END                                      4  ~32     ~33, '%29%7C%5B%3B%5D%29'
         26        CONCAT                                           ~36     ~25, ~32
         27        ASSIGN                                                   !10, ~36
   16    28        ROPE_INIT                                     5  ~39     '%2F'
         29        ROPE_ADD                                      1  ~39     ~39, !10
         30        ROPE_ADD                                      2  ~39     ~39, '%7C%28'
         31        ROPE_ADD                                      3  ~39     ~39, !9
         32        ROPE_END                                      4  ~38     ~39, '%29%2F'
         33        ASSIGN                                                   !11, ~38
   17    34        INIT_FCALL                                               'preg_match_all'
         35        SEND_VAR                                                 !11
         36        SEND_VAR                                                 !0
         37        SEND_REF                                                 !12
         38        DO_ICALL                                         $43     
         39        BOOL_NOT                                         ~44     $43
         40      > JMPZ                                                     ~44, ->43
   19    41    >   ASSIGN                                                   !1, 'not+a+serialized+string'
   20    42      > RETURN                                                   <false>
   22    43    >   ASSIGN                                                   !13, 0
   23    44        FETCH_DIM_R                                      ~47     !12, 1
         45      > FE_RESET_R                                       $48     ~47, ->122
         46    > > FE_FETCH_R                                       ~49     $48, !14, ->122
         47    >   ASSIGN                                                   !15, ~49
   25    48        ISSET_ISEMPTY_CV                                 ~51     !14
         49        BOOL_NOT                                         ~52     ~51
         50      > JMPZ_EX                                          ~52     ~52, ->57
         51    >   IS_NOT_EQUAL                                     ~53     !14, !3
         52        IS_NOT_EQUAL                                     ~54     !14, !2
         53        BOOL_XOR                                         ~55     ~53, ~54
         54        IS_NOT_EQUAL                                     ~56     !14, !4
         55        BOOL_XOR                                         ~57     ~55, ~56
         56        BOOL                                             ~52     ~57
         57    > > JMPZ                                                     ~52, ->61
   27    58    >   ASSIGN                                                   !1, 'undefined+datatype'
   28    59        FE_FREE                                                  $48
         60      > RETURN                                                   <false>
   30    61    >   IS_EQUAL                                                 !14, !3
         62      > JMPZ                                                     ~59, ->71
   32    63    >   PRE_INC                                                  !13
   33    64        FETCH_DIM_R                                      ~61     !12, 3
         65        FETCH_DIM_R                                      ~62     ~61, !15
         66        IS_NOT_EQUAL                                             ~62, '%7B'
         67      > JMPZ                                                     ~63, ->71
   35    68    >   ASSIGN                                                   !1, 'open+tag+expected'
   36    69        FE_FREE                                                  $48
         70      > RETURN                                                   <false>
   39    71    >   IS_EQUAL                                                 !14, ''
         72      > JMPZ                                                     ~65, ->81
   41    73    >   FETCH_DIM_R                                      ~66     !12, 4
         74        FETCH_DIM_R                                      ~67     ~66, !15
         75        IS_NOT_EQUAL                                             ~67, '%7D'
         76      > JMPZ                                                     ~68, ->80
   43    77    >   ASSIGN                                                   !1, 'close+tag+expected'
   44    78        FE_FREE                                                  $48
         79      > RETURN                                                   <false>
   46    80    >   PRE_DEC                                                  !13
   48    81    >   IS_EQUAL                                                 !14, !2
         82      > JMPZ                                                     ~71, ->103
   50    83    >   INIT_FCALL                                               'ltrim'
         84        FETCH_DIM_R                                      ~72     !12, 3
         85        FETCH_DIM_R                                      ~73     ~72, !15
         86        SEND_VAL                                                 ~73
         87        SEND_VAL                                                 '%22'
         88        DO_ICALL                                         $74     
         89        ASSIGN                                                   !16, $74
   51    90        INIT_FCALL                                               'rtrim'
         91        SEND_VAR                                                 !16
         92        SEND_VAL                                                 '%22%3B'
         93        DO_ICALL                                         $76     
         94        ASSIGN                                                   !16, $76
   52    95        STRLEN                                           ~78     !16
         96        FETCH_DIM_R                                      ~79     !12, 2
         97        FETCH_DIM_R                                      ~80     ~79, !15
         98        IS_NOT_EQUAL                                             ~78, ~80
         99      > JMPZ                                                     ~81, ->103
   54   100    >   ASSIGN                                                   !1, 'stringlen+for+string+not+match'
   55   101        FE_FREE                                                  $48
        102      > RETURN                                                   <false>
   58   103    >   IS_EQUAL                                                 !14, !4
        104      > JMPZ                                                     ~83, ->121
   60   105    >   FETCH_DIM_IS                                     ~84     !12, 3
        106        ISSET_ISEMPTY_DIM_OBJ                         1  ~85     ~84, !15
        107        BOOL_NOT                                         ~86     ~85
        108      > JMPZ                                                     ~86, ->112
   62   109    >   ASSIGN                                                   !1, 'unexpected+data'
   63   110        FE_FREE                                                  $48
        111      > RETURN                                                   <false>
   65   112    >   FETCH_DIM_R                                      ~88     !12, 2
        113        FETCH_DIM_R                                      ~89     ~88, !15
        114        CAST                                          4  ~90     ~89
        115        TYPE_CHECK                                   16  ~91     ~90
        116        BOOL_NOT                                         ~92     ~91
        117      > JMPZ                                                     ~92, ->121
   67   118    >   ASSIGN                                                   !1, 'integer+expected'
   68   119        FE_FREE                                                  $48
        120      > RETURN                                                   <false>
   23   121    > > JMP                                                      ->46
        122    >   FE_FREE                                                  $48
   72   123        IS_NOT_EQUAL                                             !13, 0
        124      > JMPZ                                                     ~94, ->127
   74   125    >   ASSIGN                                                   !1, 'wrong+setted+arrays'
   75   126      > RETURN                                                   <false>
   77   127    > > RETURN                                                   <true>
   78   128*     > RETURN                                                   null

End of function wd_check_serialization

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.93 ms | 1411 KiB | 22 Q