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 "Baz", // userland class extending internal class implementing Serializable ); 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); } } class Baz extends ArrayObject {} 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"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 27
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 25
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/mL7kC
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>
   27     1        DECLARE_CLASS                                            'bar'
   41     2      > FE_RESET_R                                       $3      !0, ->27
          3    > > FE_FETCH_R                                               $3, !1, ->27
   42     4    >   NOP                                                      
          5        FAST_CONCAT                                      ~4      !1, '%0A'
          6        ECHO                                                     ~4
   43     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'instanitatewithoutconstructorthroughunserialize'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $5      
         11        SEND_VAR                                                 $5
         12        DO_ICALL                                                 
   44    13        INIT_FCALL                                               'version_compare'
         14        SEND_VAL                                                 '8.0.0'
         15        SEND_VAL                                                 '5.4.0'
         16        DO_ICALL                                         $7      
         17        IS_SMALLER_OR_EQUAL                                      0, $7
         18      > JMPZ                                                     ~8, ->25
   45    19    >   INIT_FCALL                                               'var_dump'
         20        INIT_FCALL                                               'instanitatewithoutconstructorthroughreflection'
         21        SEND_VAR                                                 !1
         22        DO_FCALL                                      0  $9      
         23        SEND_VAR                                                 $9
         24        DO_ICALL                                                 
   47    25    >   ECHO                                                     '%0A'
   41    26      > JMP                                                      ->3
         27    >   FE_FREE                                                  $3
   48    28      > RETURN                                                   1

Function instanitatewithoutconstructorthroughunserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mL7kC
function name:  instanitateWithoutConstructorThroughUnserialize
number of ops:  12
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     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
   14    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/mL7kC
function name:  instanitateWithoutConstructorThroughReflection
number of ops:  12
compiled vars:  !0 = $className, !1 = $ref, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        NEW                                              $3      'ReflectionClass'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   19     5        INIT_METHOD_CALL                                         !1, 'newInstanceWithoutConstructor'
          6        DO_FCALL                                      0  $6      
          7      > RETURN                                                   $6
          8*       JMP                                                      ->11
   20     9  E > > CATCH                                       last         'ReflectionException'
   21    10    > > RETURN                                                   !2
   23    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/mL7kC
function name:  serialize
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'serialize'
          1        FETCH_OBJ_R                                      ~0      'data'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   32     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/mL7kC
function name:  unserialize
number of ops:  7
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        INIT_FCALL                                               'unserialize'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               'data'
          5        OP_DATA                                                  $2
   36     6      > RETURN                                                   null

End of function unserialize

End of class Bar.

Class Baz: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.94 ms | 1407 KiB | 25 Q