3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function maybe_unserialize( $original ) { if ( is_serialized( $original ) ) return @unserialize( $original ); return $original; } 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; $length = strlen( $data ); if ( $length < 4 ) return false; if ( ':' !== $data[1] ) return false; if ( $strict ) { $lastc = $data[ $length - 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 ( '"' !== $data[ $length - 2 ] ) return false; } elseif ( false === strpos( $data, '"' ) ) { return false; } // or else fall through case 'a' : case 'O' : 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 maybe_serialize( $data ) { if ( is_array( $data ) || is_object( $data ) ) return serialize( $data ); // Double serialization is required for backward compatibility. // See http://core.trac.wordpress.org/ticket/12930 if ( is_serialized( $data, false ) ) return serialize( $data ); return $data; } $a = 's:4\0:"ryat";'; var_dump(unserialize($a));
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/bDKAl
function name:  (null)
number of ops:  11
compiled vars:  !0 = $a
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   NOP                                                      
   8     1        NOP                                                      
  58     2        NOP                                                      
  70     3        ASSIGN                                                   !0, 's%3A4%5C0%3A%22ryat%22%3B'
  71     4        INIT_FCALL                                               'var_dump'
         5        INIT_FCALL                                               'unserialize'
         6        SEND_VAR                                                 !0
         7        DO_ICALL                                         $2      
         8        SEND_VAR                                                 $2
         9        DO_ICALL                                                 
        10      > RETURN                                                   1

Function maybe_unserialize:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
Jump found. Position 1 = -2
Branch analysis from position: 11
Jump found. Position 1 = -2
filename:       /in/bDKAl
function name:  maybe_unserialize
number of ops:  13
compiled vars:  !0 = $original
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   RECV                                             !0      
   3     1        INIT_FCALL_BY_NAME                                       'is_serialized'
         2        SEND_VAR_EX                                              !0
         3        DO_FCALL                                      0  $1      
         4      > JMPZ                                                     $1, ->11
   4     5    >   BEGIN_SILENCE                                    ~2      
         6        INIT_FCALL                                               'unserialize'
         7        SEND_VAR                                                 !0
         8        DO_ICALL                                         $3      
         9        END_SILENCE                                              ~2
        10      > RETURN                                                   $3
   5    11    > > RETURN                                                   !0
   6    12*     > RETURN                                                   null

End of function maybe_unserialize

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

End of function is_serialized

Function maybe_serialize:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
Jump found. Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
Jump found. Position 1 = -2
Branch analysis from position: 10
Jump found. Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
Jump found. Position 1 = -2
Branch analysis from position: 19
Jump found. Position 1 = -2
Branch analysis from position: 5
filename:       /in/bDKAl
function name:  maybe_serialize
number of ops:  21
compiled vars:  !0 = $data
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  58     0  E >   RECV                                             !0      
  59     1        TYPE_CHECK                                    7  ~1      !0
         2      > JMPNZ_EX                                         ~1      ~1, ->5
         3    >   TYPE_CHECK                                    8  ~2      !0
         4        BOOL                                             ~1      ~2
         5    > > JMPZ                                                     ~1, ->10
  60     6    >   INIT_FCALL                                               'serialize'
         7        SEND_VAR                                                 !0
         8        DO_ICALL                                         $3      
         9      > RETURN                                                   $3
  64    10    >   INIT_FCALL                                               'is_serialized'
        11        SEND_VAR                                                 !0
        12        SEND_VAL                                                 <false>
        13        DO_FCALL                                      0  $4      
        14      > JMPZ                                                     $4, ->19
  65    15    >   INIT_FCALL                                               'serialize'
        16        SEND_VAR                                                 !0
        17        DO_ICALL                                         $5      
        18      > RETURN                                                   $5
  67    19    > > RETURN                                                   !0
  68    20*     > RETURN                                                   null

End of function maybe_serialize

Generated using Vulcan Logic Dumper, using php 7.2.0