3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('FILTER_STRUCT_FORCE_ARRAY', "\0FILTER_STRUCT_FORCE_ARRAY\0"); function filter_struct_utf8($type, array $default) { static $is_recursive_static = false; $is_recursive = $is_recursive_static; if (!$is_recursive) { $types = array( INPUT_GET => $_GET, INPUT_POST => $_POST, INPUT_COOKIE => $_COOKIE, INPUT_REQUEST => $_REQUEST, INPUT_ENV => $_ENV, INPUT_SERVER => $_SERVER, ); $type = (int)$type; if (!isset($types[$type])) { return $default; } $var = $types[$type]; $is_recursive_static = true; } else { $var = $type; } $ret = array(); foreach ($default as $key => $value) { if ($value === FILTER_STRUCT_FORCE_ARRAY) { $ret[$key] = array(); $arr = isset($var[$key]) ? (array)$var[$key] : array(); foreach ($arr as $k => $v) { if (is_string($v) && preg_match('//u', $k) && preg_match('//u', $v)) { $ret[$key][$k] = $v; } } } elseif (!isset($var[$key])) { $ret[$key] = $value; } elseif (is_array($value)) { $ret[$key] = filter_struct_utf8($var[$key], $value); } elseif (is_array($var[$key]) || !preg_match('//u', $var[$key])) { $ret[$key] = $value; } else { $ret[$key] = $var[$key]; } } if (!$is_recursive) { $is_recursive_static = false; } return $ret; } // テスト用として代入($_POST['email']は未定義) $_POST['name'] = array( // 異常な値(本来は文字列で来るはず) 'hahaha' => 'I am an array', ); $_POST['age'] = '20'; // 正常な値 $_POST['gender'] = 'male'; // 正常な値 $_POST['options'] = array( 'b' => 'yes', // 正常な値 'c' => array('hahaha' => 'This is an invalid option'), // 異常な値(本来は配列はネストしないはず) ); // $_POSTの要素を期待する形になるようにシンボルテーブルにインポートする extract(filter_struct_utf8(INPUT_POST, array( 'name' => '', // 異常なときは強制的に空文字列にする 'age' => '', // 異常なときは強制的に空文字列にする 'email' => '', // 異常なときは強制的に空文字列にする 'gender' => '', // 異常なときは強制的に空文字列にする 'options' => FILTER_STRUCT_FORCE_ARRAY, // 強制的に一次元配列にする ))); // 値を見てみる var_dump($name, $age, $email, $gender, $options);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mcfIR
function name:  (null)
number of ops:  37
compiled vars:  !0 = $name, !1 = $age, !2 = $email, !3 = $gender, !4 = $options
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'FILTER_STRUCT_FORCE_ARRAY'
          2        SEND_VAL                                                 '%00FILTER_STRUCT_FORCE_ARRAY%00'
          3        DO_ICALL                                                 
   53     4        FETCH_W                      global              $6      '_POST'
          5        ASSIGN_DIM                                               $6, 'name'
   54     6        OP_DATA                                                  <array>
   56     7        FETCH_W                      global              $8      '_POST'
          8        ASSIGN_DIM                                               $8, 'age'
          9        OP_DATA                                                  '20'
   57    10        FETCH_W                      global              $10     '_POST'
         11        ASSIGN_DIM                                               $10, 'gender'
         12        OP_DATA                                                  'male'
   58    13        FETCH_W                      global              $12     '_POST'
         14        ASSIGN_DIM                                               $12, 'options'
   59    15        OP_DATA                                                  <array>
   64    16        INIT_FCALL                                               'extract'
         17        INIT_FCALL                                               'filter_struct_utf8'
         18        SEND_VAL                                                 0
   65    19        INIT_ARRAY                                       ~14     '', 'name'
   66    20        ADD_ARRAY_ELEMENT                                ~14     '', 'age'
   67    21        ADD_ARRAY_ELEMENT                                ~14     '', 'email'
   68    22        ADD_ARRAY_ELEMENT                                ~14     '', 'gender'
   69    23        FETCH_CONSTANT                                   ~15     'FILTER_STRUCT_FORCE_ARRAY'
         24        ADD_ARRAY_ELEMENT                                ~14     ~15, 'options'
         25        SEND_VAL                                                 ~14
         26        DO_FCALL                                      0  $16     
         27        SEND_VAL                                                 $16
         28        DO_ICALL                                                 
   73    29        INIT_FCALL                                               'var_dump'
         30        SEND_VAR                                                 !0
         31        SEND_VAR                                                 !1
         32        SEND_VAR                                                 !2
         33        SEND_VAR                                                 !3
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Function filter_struct_utf8:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 30
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 106
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 106
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 71
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 46
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
2 jumps found. (Code = 77) Position 1 = 49, Position 2 = 69
Branch analysis from position: 49
2 jumps found. (Code = 78) Position 1 = 50, Position 2 = 69
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 53, Position 2 = 58
Branch analysis from position: 53
2 jumps found. (Code = 46) Position 1 = 59, Position 2 = 64
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 68
Branch analysis from position: 64
Branch analysis from position: 58
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 69
Branch analysis from position: 46
2 jumps found. (Code = 77) Position 1 = 49, Position 2 = 69
Branch analysis from position: 49
Branch analysis from position: 69
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 77
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 88
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
Branch analysis from position: 88
2 jumps found. (Code = 47) Position 1 = 91, Position 2 = 98
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 99, Position 2 = 102
Branch analysis from position: 99
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 98
Branch analysis from position: 106
2 jumps found. (Code = 43) Position 1 = 109, Position 2 = 110
Branch analysis from position: 109
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 110
Branch analysis from position: 106
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 106
Branch analysis from position: 33
Branch analysis from position: 106
filename:       /in/mcfIR
function name:  filter_struct_utf8
number of ops:  112
compiled vars:  !0 = $type, !1 = $default, !2 = $is_recursive_static, !3 = $is_recursive, !4 = $types, !5 = $var, !6 = $ret, !7 = $value, !8 = $key, !9 = $arr, !10 = $v, !11 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        BIND_STATIC                                              !2
    6     3        ASSIGN                                                   !3, !2
    7     4        BOOL_NOT                                         ~13     !3
          5      > JMPZ                                                     ~13, ->30
    9     6    >   FETCH_R                      global              ~14     '_GET'
          7        INIT_ARRAY                                       ~15     ~14, 1
   10     8        FETCH_R                      global              ~16     '_POST'
          9        ADD_ARRAY_ELEMENT                                ~15     ~16, 0
   11    10        FETCH_R                      global              ~17     '_COOKIE'
         11        ADD_ARRAY_ELEMENT                                ~15     ~17, 2
   12    12        FETCH_CONSTANT                                   ~18     'INPUT_REQUEST'
         13        FETCH_R                      global              ~19     '_REQUEST'
         14        ADD_ARRAY_ELEMENT                                ~15     ~19, ~18
   13    15        FETCH_R                      global              ~20     '_ENV'
         16        ADD_ARRAY_ELEMENT                                ~15     ~20, 4
   14    17        FETCH_R                      global              ~21     '_SERVER'
         18        ADD_ARRAY_ELEMENT                                ~15     ~21, 5
    8    19        ASSIGN                                                   !4, ~15
   16    20        CAST                                          4  ~23     !0
         21        ASSIGN                                                   !0, ~23
   17    22        ISSET_ISEMPTY_DIM_OBJ                         0  ~25     !4, !0
         23        BOOL_NOT                                         ~26     ~25
         24      > JMPZ                                                     ~26, ->26
   18    25    > > RETURN                                                   !1
   20    26    >   FETCH_DIM_R                                      ~27     !4, !0
         27        ASSIGN                                                   !5, ~27
   21    28        ASSIGN                                                   !2, <true>
         29      > JMP                                                      ->31
   23    30    >   ASSIGN                                                   !5, !0
   25    31    >   ASSIGN                                                   !6, <array>
   26    32      > FE_RESET_R                                       $32     !1, ->106
         33    > > FE_FETCH_R                                       ~33     $32, !7, ->106
         34    >   ASSIGN                                                   !8, ~33
   27    35        FETCH_CONSTANT                                   ~35     'FILTER_STRUCT_FORCE_ARRAY'
         36        IS_IDENTICAL                                             !7, ~35
         37      > JMPZ                                                     ~36, ->71
   28    38    >   ASSIGN_DIM                                               !6, !8
         39        OP_DATA                                                  <array>
   29    40        ISSET_ISEMPTY_DIM_OBJ                         0          !5, !8
         41      > JMPZ                                                     ~38, ->46
         42    >   FETCH_DIM_R                                      ~39     !5, !8
         43        CAST                                          7  ~40     ~39
         44        QM_ASSIGN                                        ~41     ~40
         45      > JMP                                                      ->47
         46    >   QM_ASSIGN                                        ~41     <array>
         47    >   ASSIGN                                                   !9, ~41
   30    48      > FE_RESET_R                                       $43     !9, ->69
         49    > > FE_FETCH_R                                       ~44     $43, !10, ->69
         50    >   ASSIGN                                                   !11, ~44
   31    51        TYPE_CHECK                                   64  ~46     !10
         52      > JMPZ_EX                                          ~46     ~46, ->58
         53    >   INIT_FCALL                                               'preg_match'
         54        SEND_VAL                                                 '%2F%2Fu'
         55        SEND_VAR                                                 !11
         56        DO_ICALL                                         $47     
         57        BOOL                                             ~46     $47
         58    > > JMPZ_EX                                          ~46     ~46, ->64
         59    >   INIT_FCALL                                               'preg_match'
         60        SEND_VAL                                                 '%2F%2Fu'
         61        SEND_VAR                                                 !10
         62        DO_ICALL                                         $48     
         63        BOOL                                             ~46     $48
         64    > > JMPZ                                                     ~46, ->68
   32    65    >   FETCH_DIM_W                                      $49     !6, !8
         66        ASSIGN_DIM                                               $49, !11
         67        OP_DATA                                                  !10
   30    68    > > JMP                                                      ->49
         69    >   FE_FREE                                                  $43
         70      > JMP                                                      ->105
   35    71    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~51     !5, !8
         72        BOOL_NOT                                         ~52     ~51
         73      > JMPZ                                                     ~52, ->77
   36    74    >   ASSIGN_DIM                                               !6, !8
         75        OP_DATA                                                  !7
         76      > JMP                                                      ->105
   37    77    >   TYPE_CHECK                                  128          !7
         78      > JMPZ                                                     ~54, ->88
   38    79    >   INIT_FCALL_BY_NAME                                       'filter_struct_utf8'
         80        CHECK_FUNC_ARG                                           
         81        FETCH_DIM_FUNC_ARG                               $56     !5, !8
         82        SEND_FUNC_ARG                                            $56
         83        SEND_VAR_EX                                              !7
         84        DO_FCALL                                      0  $57     
         85        ASSIGN_DIM                                               !6, !8
         86        OP_DATA                                                  $57
         87      > JMP                                                      ->105
   39    88    >   FETCH_DIM_R                                      ~58     !5, !8
         89        TYPE_CHECK                                  128  ~59     ~58
         90      > JMPNZ_EX                                         ~59     ~59, ->98
         91    >   INIT_FCALL                                               'preg_match'
         92        SEND_VAL                                                 '%2F%2Fu'
         93        FETCH_DIM_R                                      ~60     !5, !8
         94        SEND_VAL                                                 ~60
         95        DO_ICALL                                         $61     
         96        BOOL_NOT                                         ~62     $61
         97        BOOL                                             ~59     ~62
         98    > > JMPZ                                                     ~59, ->102
   40    99    >   ASSIGN_DIM                                               !6, !8
        100        OP_DATA                                                  !7
        101      > JMP                                                      ->105
   42   102    >   FETCH_DIM_R                                      ~65     !5, !8
        103        ASSIGN_DIM                                               !6, !8
        104        OP_DATA                                                  ~65
   26   105    > > JMP                                                      ->33
        106    >   FE_FREE                                                  $32
   45   107        BOOL_NOT                                         ~66     !3
        108      > JMPZ                                                     ~66, ->110
   46   109    >   ASSIGN                                                   !2, <false>
   48   110    > > RETURN                                                   !6
   49   111*     > RETURN                                                   null

End of function filter_struct_utf8

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.34 ms | 1415 KiB | 22 Q