3v4l.org

run code in 300+ PHP versions simultaneously
<?php $classNames = array( "Foo", // userland class "StdClass", // class defined by php-src, but still not considered as internal "Bar", // userland class implementing Serializable "ReflectionClass", // internal class "ArrayObject", // internal class implementing Serializable ); foreach($classNames as $className) { echo "$className\n"; var_dump(instanitateWithoutConstructorThroughUnserialize($className)); if (version_compare(PHP_VERSION, '5.4.0') >= 0) { var_dump(instanitateWithoutConstructorThroughReflection($className)); } echo "\n"; } function instanitateWithoutConstructorThroughUnserialize($className) { return unserialize(sprintf('O:%d:"%s":0:{}', strlen($className), $className)); } function instanitateWithoutConstructorThroughReflection($className) { try { $ref = new ReflectionClass($className); return $ref->newInstanceWithoutConstructor(); } catch (ReflectionException $e) { return $e; } } class Foo {} Class Bar implements Serializable { private $data; public function serialize() { return serialize($this->data); } public function unserialize($data) { $this->data = unserialize($data); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 26
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 24
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 24
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/8rR3m
function name:  (null)
number of ops:  29
compiled vars:  !0 = $classNames, !1 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1      > FE_RESET_R                                       $3      !0, ->26
          2    > > FE_FETCH_R                                               $3, !1, ->26
   12     3    >   NOP                                                      
          4        FAST_CONCAT                                      ~4      !1, '%0A'
          5        ECHO                                                     ~4
   13     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL_BY_NAME                                       'instanitateWithoutConstructorThroughUnserialize'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0  $5      
         10        SEND_VAR                                                 $5
         11        DO_ICALL                                                 
   14    12        INIT_FCALL                                               'version_compare'
         13        SEND_VAL                                                 '8.0.0'
         14        SEND_VAL                                                 '5.4.0'
         15        DO_ICALL                                         $7      
         16        IS_SMALLER_OR_EQUAL                                      0, $7
         17      > JMPZ                                                     ~8, ->24
   15    18    >   INIT_FCALL                                               'var_dump'
         19        INIT_FCALL_BY_NAME                                       'instanitateWithoutConstructorThroughReflection'
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0  $9      
         22        SEND_VAR                                                 $9
         23        DO_ICALL                                                 
   17    24    >   ECHO                                                     '%0A'
   11    25      > JMP                                                      ->2
         26    >   FE_FREE                                                  $3
   35    27        DECLARE_CLASS                                            'bar'
   45    28      > RETURN                                                   1

Function instanitatewithoutconstructorthroughunserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8rR3m
function name:  instanitateWithoutConstructorThroughUnserialize
number of ops:  12
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'unserialize'
          2        INIT_FCALL                                               'sprintf'
          3        SEND_VAL                                                 'O%3A%25d%3A%22%25s%22%3A0%3A%7B%7D'
          4        STRLEN                                           ~1      !0
          5        SEND_VAL                                                 ~1
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                         $3      
         10      > RETURN                                                   $3
   22    11*     > RETURN                                                   null

End of function instanitatewithoutconstructorthroughunserialize

Function instanitatewithoutconstructorthroughreflection:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 9
Branch analysis from position: 9
2 jumps found. (Code = 107) Position 1 = 10, Position 2 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8rR3m
function name:  instanitateWithoutConstructorThroughReflection
number of ops:  12
compiled vars:  !0 = $className, !1 = $ref, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        NEW                                              $3      'ReflectionClass'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   27     5        INIT_METHOD_CALL                                         !1, 'newInstanceWithoutConstructor'
          6        DO_FCALL                                      0  $6      
          7      > RETURN                                                   $6
          8*       JMP                                                      ->11
   28     9  E > > CATCH                                       last         'ReflectionException'
   29    10    > > RETURN                                                   !2
   31    11*     > RETURN                                                   null

End of function instanitatewithoutconstructorthroughreflection

Class Foo: [no user functions]
Class Bar:
Function serialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8rR3m
function name:  serialize
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   INIT_FCALL                                               'serialize'
          1        FETCH_OBJ_R                                      ~0      'data'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   40     5*     > RETURN                                                   null

End of function serialize

Function unserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8rR3m
function name:  unserialize
number of ops:  7
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'unserialize'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               'data'
          5        OP_DATA                                                  $2
   44     6      > RETURN                                                   null

End of function unserialize

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.57 ms | 1409 KiB | 23 Q