3v4l.org

run code in 300+ PHP versions simultaneously
<?php $errmsg = NULL; function wd_check_serialization( $string ) { $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 ) ) { echo 'undefined datatype'; return false; } if( $value == $array ) { $open_arrays++; if( $matches[3][$key] != '{' ) { echo '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] ) { echo 'stringlen for string not match'; return false; } } if( $value == $integer ) { if( !empty( $matches[3][$key] ) ) { echo 'unexpected data'; return false; } if( !is_integer( (int)$matches[2][$key] ) ) { $errmsg = 'integer expected'; return false; } } } if( $open_arrays != 0 ) { echo '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/dpVMq
function name:  (null)
number of ops:  8
compiled vars:  !0 = $errmsg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, null
   82     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'wd_check_serialization'
          3        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'
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

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

End of function wd_check_serialization

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.22 ms | 1415 KiB | 22 Q