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 "ReflectionClass", // internal class "ArrayObject", // internal class implementing Serializable ); foreach($classNames as $className) { print_r("-----------$className-----------"); var_dump(instanitateWithoutConstructorThroughUnserialize($className)); if (version_compare(PHP_VERSION, '5.4.0') >= 0) { var_dump(instanitateWithoutConstructorThroughReflection($className)); } print_r("----------------------"); } 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 {}
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 31
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 31
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 27
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/4ZKKW
function name:  (null)
number of ops:  33
compiled vars:  !0 = $classNames, !1 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1      > FE_RESET_R                                       $3      !0, ->31
          2    > > FE_FETCH_R                                               $3, !1, ->31
   11     3    >   INIT_FCALL                                               'print_r'
          4        ROPE_INIT                                     3  ~5      '-----------'
          5        ROPE_ADD                                      1  ~5      ~5, !1
          6        ROPE_END                                      2  ~4      ~5, '-----------'
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                                 
   12     9        INIT_FCALL                                               'var_dump'
         10        INIT_FCALL_BY_NAME                                       'instanitateWithoutConstructorThroughUnserialize'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0  $8      
         13        SEND_VAR                                                 $8
         14        DO_ICALL                                                 
   13    15        INIT_FCALL                                               'version_compare'
         16        SEND_VAL                                                 '8.0.0'
         17        SEND_VAL                                                 '5.4.0'
         18        DO_ICALL                                         $10     
         19        IS_SMALLER_OR_EQUAL                                      0, $10
         20      > JMPZ                                                     ~11, ->27
   14    21    >   INIT_FCALL                                               'var_dump'
         22        INIT_FCALL_BY_NAME                                       'instanitateWithoutConstructorThroughReflection'
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0  $12     
         25        SEND_VAR                                                 $12
         26        DO_ICALL                                                 
   16    27    >   INIT_FCALL                                               'print_r'
         28        SEND_VAL                                                 '----------------------'
         29        DO_ICALL                                                 
   10    30      > JMP                                                      ->2
         31    >   FE_FREE                                                  $3
   32    32      > RETURN                                                   1

Function instanitatewithoutconstructorthroughunserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4ZKKW
function name:  instanitateWithoutConstructorThroughUnserialize
number of ops:  12
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     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
   21    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/4ZKKW
function name:  instanitateWithoutConstructorThroughReflection
number of ops:  12
compiled vars:  !0 = $className, !1 = $ref, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        NEW                                              $3      'ReflectionClass'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   26     5        INIT_METHOD_CALL                                         !1, 'newInstanceWithoutConstructor'
          6        DO_FCALL                                      0  $6      
          7      > RETURN                                                   $6
          8*       JMP                                                      ->11
   27     9  E > > CATCH                                       last         'ReflectionException'
   28    10    > > RETURN                                                   !2
   30    11*     > RETURN                                                   null

End of function instanitatewithoutconstructorthroughreflection

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.61 ms | 1400 KiB | 23 Q