3v4l.org

run code in 300+ PHP versions simultaneously
<?php class testClass_forSerialize implements Serializable { public function serialize() { static $count = 0; static $objectHashes = []; $ret = new \stdClass(); $serializedData = serialize($ret); $objectHash = spl_object_hash($ret); echo "loop $count: ObjectHash $objectHash Received: ".$serializedData."\n"; if (array_key_exists($objectHash, $objectHashes) == true) { echo "Object hash already exists - serialize is going to be sad.\n"; } $objectHashes[$objectHash] = $count; if (@unserialize($serializedData) === false) { printf( "borked, serialize of %s returned %s which could not be unserialized.\n", var_export($ret, true), $serializedData ); exit(0); } echo "loop $count: Returning '$serializedData'\n"; $count++; return $serializedData; } public function unserialize($data) { throw new \Exception("not relevant"); } } $list = []; for ($i=0; $i<2; $i++) { $list[] = new \testClass_forSerialize(); } $ser = serialize($list);
based on 7vCcn
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
Branch analysis from position: 4
filename:       /in/9ttkq
function name:  (null)
number of ops:  17
compiled vars:  !0 = $list, !1 = $i, !2 = $ser
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   ADD_INTERFACE                                            'testclass_forserialize'
  38     1        QM_ASSIGN                                                !0
  39     2        QM_ASSIGN                                                !1
         3      > JMP                                                      ->10
  40     4    >   NEW                                              $6      :25
         5        DO_FCALL                                      0          
         6        ASSIGN_ADD                                    0          !0
         7        OP_DATA                                                  $6
  39     8        POST_INC                                         ~8      !1
         9        FREE                                                     ~8
        10    >   IS_SMALLER_OR_EQUAL                              ~9      !1, 2
        11      > JMPNZ                                                    ~9, ->4
  43    12    >   INIT_FCALL                                               'serialize'
        13        SEND_VAR                                                 !0
        14        DO_ICALL                                         $10     
        15        QM_ASSIGN                                                !2
        16      > RETURN                                                   1

Class testClass_forSerialize:
Function serialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 44
Branch analysis from position: 34
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/9ttkq
function name:  serialize
number of ops:  54
compiled vars:  !0 = $count, !1 = $objectHashes, !2 = $ret, !3 = $serializedData, !4 = $objectHash
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   5     0  E >   BIND_STATIC                                              !0
   6     1        BIND_STATIC                                              !1
   7     2        NEW                                              $5      :99
         3        DO_FCALL                                      0          
         4        QM_ASSIGN                                                !2
   8     5        INIT_FCALL                                               'serialize'
         6        SEND_VAR                                                 !2
         7        DO_ICALL                                         $8      
         8        QM_ASSIGN                                                !3
  10     9        INIT_FCALL                                               'spl_object_hash'
        10        SEND_VAR                                                 !2
        11        DO_ICALL                                         $10     
        12        QM_ASSIGN                                                !4
  11    13        ROPE_INIT                                     5  ~13     'loop+'
        14        ROPE_ADD                                      1  ~13     ~13, !0
        15        ROPE_ADD                                      2  ~13     ~13, '%3A+ObjectHash+'
        16        ROPE_ADD                                      3  ~13     ~13, !4
        17        ROPE_END                                      4  ~12     ~13, '+Received%3A+'
        18        CONCAT                                           ~16     ~12, !3
        19        CONCAT                                           ~17     ~16, '%0A'
        20        ASSIGN_OBJ                                               ~17
  12    21        FUNC_NUM_ARGS                                    ~18     !4, !1
        22        BOOL                                             ~19     ~18
        23      > JMPZ                                                     ~19, ->25
  13    24    >   ASSIGN_OBJ                                               'Object+hash+already+exists+-+serialize+is+going+to+be+sad.%0A'
  16    25    >   ASSIGN_ADD                                    0          !1, !4
        26        OP_DATA                                                  !0
  18    27        BEGIN_SILENCE                                    ~21     
        28        INIT_FCALL                                               'unserialize'
        29        SEND_VAR                                                 !3
        30        DO_ICALL                                         $22     
        31        END_SILENCE                                              ~21
        32        IS_NOT_IDENTICAL                                 ~23     $22, <false>
        33      > JMPZ                                                     ~23, ->44
  19    34    >   INIT_FCALL                                               'printf'
  20    35        SEND_VAL                                                 'borked%2C+serialize+of+%25s+returned+%25s+which+could+not+be+unserialized.%0A'
  21    36        INIT_FCALL                                               'var_export'
        37        SEND_VAR                                                 !2
        38        SEND_VAL                                                 <true>
        39        DO_ICALL                                         $24     
        40        SEND_VAR                                                 $24
  22    41        SEND_VAR                                                 !3
        42        DO_ICALL                                                 
  24    43      > EXIT                                                     0
  27    44    >   ROPE_INIT                                     5  ~27     'loop+'
        45        ROPE_ADD                                      1  ~27     ~27, !0
        46        ROPE_ADD                                      2  ~27     ~27, '%3A+Returning+%27'
        47        ROPE_ADD                                      3  ~27     ~27, !3
        48        ROPE_END                                      4  ~26     ~27, '%27%0A'
        49        ASSIGN_OBJ                                               ~26
  28    50        POST_INC                                         ~30     !0
        51        FREE                                                     ~30
  29    52      > RETURN                                                   !3
  30    53*     > RETURN                                                   null

End of function serialize

Function unserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/9ttkq
function name:  unserialize
number of ops:  6
compiled vars:  !0 = $data
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  32     0  E >   RECV                                             !0      
  33     1        NEW                                              $1      :5
         2        SEND_VAL_EX                                              'not+relevant'
         3        DO_FCALL                                      0          
         4      > THROW                                         0          $1
  34     5*     > RETURN                                                   null

End of function unserialize

End of class testClass_forSerialize.

Generated using Vulcan Logic Dumper, using php 7.4.0