3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Polyfills. */ function stripslashes_from_strings_only( $value ) { return is_string( $value ) ? stripslashes( $value ) : $value; } function is_serialized( $data, $strict = true ) { // If it isn't a string, it isn't serialized. if ( ! is_string( $data ) ) { return false; } $data = trim( $data ); if ( 'N;' === $data ) { return true; } if ( strlen( $data ) < 4 ) { return false; } if ( ':' !== $data[1] ) { return false; } if ( $strict ) { $lastc = substr( $data, -1 ); if ( ';' !== $lastc && '}' !== $lastc ) { return false; } } else { $semicolon = strpos( $data, ';' ); $brace = strpos( $data, '}' ); // Either ; or } must exist. if ( false === $semicolon && false === $brace ) { return false; } // But neither must be in the first X characters. if ( false !== $semicolon && $semicolon < 3 ) { return false; } if ( false !== $brace && $brace < 4 ) { return false; } } $token = $data[0]; switch ( $token ) { case 's': if ( $strict ) { if ( '"' !== substr( $data, -2, 1 ) ) { return false; } } elseif ( false === strpos( $data, '"' ) ) { return false; } // Or else fall through. case 'a': case 'O': case 'E': return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); case 'b': case 'i': case 'd': $end = $strict ? '$' : ''; return (bool) preg_match( "/^{$token}:[0-9.E+-]+;$end/", $data ); } return false; } function map_deep( $value, $callback ) { if ( is_array( $value ) ) { foreach ( $value as $index => $item ) { $value[ $index ] = map_deep( $item, $callback ); } } elseif ( is_object( $value ) ) { $object_vars = get_object_vars( $value ); foreach ( $object_vars as $property_name => $property_value ) { $value->$property_name = map_deep( $property_value, $callback ); } } else { $value = call_user_func( $callback, $value ); } return $value; } function maybe_unserialize( $data ) { if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in. return @unserialize( trim( $data ) ); } return $data; } /* * Test. */ $test_data = 'a:2:{i:0;O:14:"SuperCustomXyz":1:{s:17:" SuperCustomXyz x";s:4:"test";}s:8:"testdata";a:2:{s:1:"a";i:1;s:1:"b";i:2;}}'; $unserialized = maybe_unserialize($test_data); $res = map_deep($unserialized, 'stripslashes_from_strings_only'); print_r($res);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WJiN0
function name:  (null)
number of ops:  14
compiled vars:  !0 = $test_data, !1 = $unserialized, !2 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   98     0  E >   ASSIGN                                                   !0, 'a%3A2%3A%7Bi%3A0%3BO%3A14%3A%22SuperCustomXyz%22%3A1%3A%7Bs%3A17%3A%22+SuperCustomXyz+x%22%3Bs%3A4%3A%22test%22%3B%7Ds%3A8%3A%22testdata%22%3Ba%3A2%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3B%7D%7D'
   99     1        INIT_FCALL                                               'maybe_unserialize'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
  100     5        INIT_FCALL                                               'map_deep'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 'stripslashes_from_strings_only'
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !2, $6
  101    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function stripslashes_from_strings_only:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WJiN0
function name:  stripslashes_from_strings_only
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~1, ->8
          3    >   INIT_FCALL                                               'stripslashes'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        QM_ASSIGN                                        ~3      $2
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~3      !0
          9    > > RETURN                                                   ~3
    8    10*     > RETURN                                                   null

End of function stripslashes_from_strings_only

Function is_serialized:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 34
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
9 jumps found. (Code = 188) Position 1 = 80, Position 2 = 97, Position 3 = 97, Position 4 = 97, Position 5 = 106, Position 6 = 106, Position 7 = 106, Position 8 = 122, Position 9 = 65
Branch analysis from position: 80
2 jumps found. (Code = 43) Position 1 = 81, Position 2 = 90
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 89
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
2 jumps found. (Code = 43) Position 1 = 96, Position 2 = 97
Branch analysis from position: 96
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 97
Branch analysis from position: 97
Branch analysis from position: 97
Branch analysis from position: 97
Branch analysis from position: 106
2 jumps found. (Code = 43) Position 1 = 107, Position 2 = 109
Branch analysis from position: 107
1 jumps found. (Code = 42) Position 1 = 110
Branch analysis from position: 110
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 109
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 106
Branch analysis from position: 106
Branch analysis from position: 122
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 80
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 97
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 97
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 97
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 106
Branch analysis from position: 75
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 106
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 106
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 122
Branch analysis from position: 122
Branch analysis from position: 106
Branch analysis from position: 106
Branch analysis from position: 106
Branch analysis from position: 97
Branch analysis from position: 97
Branch analysis from position: 97
Branch analysis from position: 80
Branch analysis from position: 31
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 50
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 56
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
2 jumps found. (Code = 46) Position 1 = 58, Position 2 = 60
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 62
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 60
Branch analysis from position: 54
Branch analysis from position: 48
filename:       /in/WJiN0
function name:  is_serialized
number of ops:  124
compiled vars:  !0 = $data, !1 = $strict, !2 = $lastc, !3 = $semicolon, !4 = $brace, !5 = $token, !6 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
   12     2        TYPE_CHECK                                   64  ~7      !0
          3        BOOL_NOT                                         ~8      ~7
          4      > JMPZ                                                     ~8, ->6
   13     5    > > RETURN                                                   <false>
   15     6    >   INIT_FCALL                                               'trim'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $9      
          9        ASSIGN                                                   !0, $9
   16    10        IS_IDENTICAL                                             !0, 'N%3B'
         11      > JMPZ                                                     ~11, ->13
   17    12    > > RETURN                                                   <true>
   19    13    >   STRLEN                                           ~12     !0
         14        IS_SMALLER                                               ~12, 4
         15      > JMPZ                                                     ~13, ->17
   20    16    > > RETURN                                                   <false>
   22    17    >   FETCH_DIM_R                                      ~14     !0, 1
         18        IS_NOT_IDENTICAL                                         ~14, '%3A'
         19      > JMPZ                                                     ~15, ->21
   23    20    > > RETURN                                                   <false>
   25    21    > > JMPZ                                                     !1, ->34
   26    22    >   INIT_FCALL                                               'substr'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 -1
         25        DO_ICALL                                         $16     
         26        ASSIGN                                                   !2, $16
   27    27        IS_NOT_IDENTICAL                                 ~18     !2, '%3B'
         28      > JMPZ_EX                                          ~18     ~18, ->31
         29    >   IS_NOT_IDENTICAL                                 ~19     !2, '%7D'
         30        BOOL                                             ~18     ~19
         31    > > JMPZ                                                     ~18, ->33
   28    32    > > RETURN                                                   <false>
   25    33    > > JMP                                                      ->62
   31    34    >   INIT_FCALL                                               'strpos'
         35        SEND_VAR                                                 !0
         36        SEND_VAL                                                 '%3B'
         37        DO_ICALL                                         $20     
         38        ASSIGN                                                   !3, $20
   32    39        INIT_FCALL                                               'strpos'
         40        SEND_VAR                                                 !0
         41        SEND_VAL                                                 '%7D'
         42        DO_ICALL                                         $22     
         43        ASSIGN                                                   !4, $22
   34    44        TYPE_CHECK                                    4  ~24     !3
         45      > JMPZ_EX                                          ~24     ~24, ->48
         46    >   TYPE_CHECK                                    4  ~25     !4
         47        BOOL                                             ~24     ~25
         48    > > JMPZ                                                     ~24, ->50
   35    49    > > RETURN                                                   <false>
   38    50    >   TYPE_CHECK                                  1018  ~26     !3
         51      > JMPZ_EX                                          ~26     ~26, ->54
         52    >   IS_SMALLER                                       ~27     !3, 3
         53        BOOL                                             ~26     ~27
         54    > > JMPZ                                                     ~26, ->56
   39    55    > > RETURN                                                   <false>
   41    56    >   TYPE_CHECK                                  1018  ~28     !4
         57      > JMPZ_EX                                          ~28     ~28, ->60
         58    >   IS_SMALLER                                       ~29     !4, 4
         59        BOOL                                             ~28     ~29
         60    > > JMPZ                                                     ~28, ->62
   42    61    > > RETURN                                                   <false>
   45    62    >   FETCH_DIM_R                                      ~30     !0, 0
         63        ASSIGN                                                   !5, ~30
   46    64      > SWITCH_STRING                                            !5, [ 's':->80, 'a':->97, 'O':->97, 'E':->97, 'b':->106, 'i':->106, 'd':->106, ], ->122
   47    65    >   IS_EQUAL                                                 !5, 's'
         66      > JMPNZ                                                    ~32, ->80
   56    67    >   IS_EQUAL                                                 !5, 'a'
         68      > JMPNZ                                                    ~32, ->97
   57    69    >   IS_EQUAL                                                 !5, 'O'
         70      > JMPNZ                                                    ~32, ->97
   58    71    >   IS_EQUAL                                                 !5, 'E'
         72      > JMPNZ                                                    ~32, ->97
   60    73    >   IS_EQUAL                                                 !5, 'b'
         74      > JMPNZ                                                    ~32, ->106
   61    75    >   IS_EQUAL                                                 !5, 'i'
         76      > JMPNZ                                                    ~32, ->106
   62    77    >   IS_EQUAL                                                 !5, 'd'
         78      > JMPNZ                                                    ~32, ->106
         79    > > JMP                                                      ->122
   48    80    > > JMPZ                                                     !1, ->90
   49    81    >   INIT_FCALL                                               'substr'
         82        SEND_VAR                                                 !0
         83        SEND_VAL                                                 -2
         84        SEND_VAL                                                 1
         85        DO_ICALL                                         $33     
         86        IS_NOT_IDENTICAL                                         $33, '%22'
         87      > JMPZ                                                     ~34, ->89
   50    88    > > RETURN                                                   <false>
   48    89    > > JMP                                                      ->97
   52    90    >   INIT_FCALL                                               'strpos'
         91        SEND_VAR                                                 !0
         92        SEND_VAL                                                 '%22'
         93        DO_ICALL                                         $35     
         94        TYPE_CHECK                                    4          $35
         95      > JMPZ                                                     ~36, ->97
   53    96    > > RETURN                                                   <false>
   59    97    >   INIT_FCALL                                               'preg_match'
         98        ROPE_INIT                                     3  ~38     '%2F%5E'
         99        ROPE_ADD                                      1  ~38     ~38, !5
        100        ROPE_END                                      2  ~37     ~38, '%3A%5B0-9%5D%2B%3A%2Fs'
        101        SEND_VAL                                                 ~37
        102        SEND_VAR                                                 !0
        103        DO_ICALL                                         $40     
        104        BOOL                                             ~41     $40
        105      > RETURN                                                   ~41
   63   106    > > JMPZ                                                     !1, ->109
        107    >   QM_ASSIGN                                        ~42     '%24'
        108      > JMP                                                      ->110
        109    >   QM_ASSIGN                                        ~42     ''
        110    >   ASSIGN                                                   !6, ~42
   64   111        INIT_FCALL                                               'preg_match'
        112        ROPE_INIT                                     5  ~45     '%2F%5E'
        113        ROPE_ADD                                      1  ~45     ~45, !5
        114        ROPE_ADD                                      2  ~45     ~45, '%3A%5B0-9.E%2B-%5D%2B%3B'
        115        ROPE_ADD                                      3  ~45     ~45, !6
        116        ROPE_END                                      4  ~44     ~45, '%2F'
        117        SEND_VAL                                                 ~44
        118        SEND_VAR                                                 !0
        119        DO_ICALL                                         $48     
        120        BOOL                                             ~49     $48
        121      > RETURN                                                   ~49
   66   122    > > RETURN                                                   <false>
   67   123*     > RETURN                                                   null

End of function is_serialized

Function map_deep:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 34
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 32
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WJiN0
function name:  map_deep
number of ops:  40
compiled vars:  !0 = $value, !1 = $callback, !2 = $item, !3 = $index, !4 = $object_vars, !5 = $property_value, !6 = $property_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   71     2        TYPE_CHECK                                  128          !0
          3      > JMPZ                                                     ~7, ->16
   72     4    > > FE_RESET_R                                       $8      !0, ->14
          5    > > FE_FETCH_R                                       ~9      $8, !2, ->14
          6    >   ASSIGN                                                   !3, ~9
   73     7        INIT_FCALL_BY_NAME                                       'map_deep'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0  $12     
         11        ASSIGN_DIM                                               !0, !3
         12        OP_DATA                                                  $12
   72    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $8
   71    15      > JMP                                                      ->38
   75    16    >   TYPE_CHECK                                  256          !0
         17      > JMPZ                                                     ~13, ->34
   76    18    >   INIT_FCALL                                               'get_object_vars'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $14     
         21        ASSIGN                                                   !4, $14
   77    22      > FE_RESET_R                                       $16     !4, ->32
         23    > > FE_FETCH_R                                       ~17     $16, !5, ->32
         24    >   ASSIGN                                                   !6, ~17
   78    25        INIT_FCALL_BY_NAME                                       'map_deep'
         26        SEND_VAR_EX                                              !5
         27        SEND_VAR_EX                                              !1
         28        DO_FCALL                                      0  $20     
         29        ASSIGN_OBJ                                               !0, !6
         30        OP_DATA                                                  $20
   77    31      > JMP                                                      ->23
         32    >   FE_FREE                                                  $16
   75    33      > JMP                                                      ->38
   81    34    >   INIT_USER_CALL                                1          'call_user_func', !1
         35        SEND_USER                                                !0
         36        DO_FCALL                                      0  $21     
         37        ASSIGN                                                   !0, $21
   84    38    > > RETURN                                                   !0
   85    39*     > RETURN                                                   null

End of function map_deep

Function maybe_unserialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WJiN0
function name:  maybe_unserialize
number of ops:  16
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
   88     1        INIT_FCALL                                               'is_serialized'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $1      
          4      > JMPZ                                                     $1, ->14
   89     5    >   BEGIN_SILENCE                                    ~2      
          6        INIT_FCALL                                               'unserialize'
          7        INIT_FCALL                                               'trim'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $3      
         10        SEND_VAR                                                 $3
         11        DO_ICALL                                         $4      
         12        END_SILENCE                                              ~2
         13      > RETURN                                                   $4
   92    14    > > RETURN                                                   !0
   93    15*     > RETURN                                                   null

End of function maybe_unserialize

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.89 ms | 1488 KiB | 24 Q