3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Sanitizer { public function sanitizeSingle(&$string) { if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) { $string = stripslashes($string); } $string = trim(htmlspecialchars($string, ENT_QUOTES)); } public function sanitize($data) { if (is_array($data)) { array_walk_recursive($data, [$this, 'sanitizeSingle']); } else { $this->sanitizeSingle($data); } return $data; } } $array = ['one' => ['a ', ' b ', ' c'], 'two' => " <a href='test'>Test</a>"]; $string = ' another "test"'; $sanitizer = new Sanitizer(); var_export($sanitizer->sanitize($array)); echo "\n---\n"; var_export($sanitizer->sanitize($string));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7drYO
function name:  (null)
number of ops:  19
compiled vars:  !0 = $array, !1 = $string, !2 = $sanitizer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   22     1        ASSIGN                                                   !1, '+another+%22test%22'
   24     2        NEW                                              $5      'Sanitizer'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $5
   25     5        INIT_FCALL                                               'var_export'
          6        INIT_METHOD_CALL                                         !2, 'sanitize'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $8      
          9        SEND_VAR                                                 $8
         10        DO_ICALL                                                 
   26    11        ECHO                                                     '%0A---%0A'
   27    12        INIT_FCALL                                               'var_export'
         13        INIT_METHOD_CALL                                         !2, 'sanitize'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0  $10     
         16        SEND_VAR                                                 $10
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Class Sanitizer:
Function sanitizesingle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/7drYO
function name:  sanitizeSingle
number of ops:  22
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'function_exists'
          2        SEND_VAL                                                 'get_magic_quotes_gpc'
          3        DO_ICALL                                         $1      
          4      > JMPZ_EX                                          ~2      $1, ->8
          5    >   INIT_FCALL_BY_NAME                                       'get_magic_quotes_gpc'
          6        DO_FCALL                                      0  $3      
          7        BOOL                                             ~2      $3
          8    > > JMPZ                                                     ~2, ->13
    6     9    >   INIT_FCALL                                               'stripslashes'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $4      
         12        ASSIGN                                                   !0, $4
    8    13    >   INIT_FCALL                                               'trim'
         14        INIT_FCALL                                               'htmlspecialchars'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 3
         17        DO_ICALL                                         $6      
         18        SEND_VAR                                                 $6
         19        DO_ICALL                                         $7      
         20        ASSIGN                                                   !0, $7
    9    21      > RETURN                                                   null

End of function sanitizesingle

Function sanitize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7drYO
function name:  sanitize
number of ops:  16
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        TYPE_CHECK                                  128          !0
          2      > JMPZ                                                     ~1, ->11
   13     3    >   INIT_FCALL                                               'array_walk_recursive'
          4        SEND_REF                                                 !0
          5        FETCH_THIS                                       ~2      
          6        INIT_ARRAY                                       ~3      ~2
          7        ADD_ARRAY_ELEMENT                                ~3      'sanitizeSingle'
          8        SEND_VAL                                                 ~3
          9        DO_ICALL                                                 
   12    10      > JMP                                                      ->14
   15    11    >   INIT_METHOD_CALL                                         'sanitizeSingle'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
   17    14    > > RETURN                                                   !0
   18    15*     > RETURN                                                   null

End of function sanitize

End of class Sanitizer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
286.59 ms | 1010 KiB | 19 Q