3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Sealed class can not be created directly */ class Seal { private function __construct() { // private ctor prevents from direct creation of instance } } #1 Via traditional reflection without constructor $refClass = new ReflectionClass(Seal::class); $instance = $refClass->newInstanceWithoutConstructor(); var_dump($instance); #2 Via closure binding to the sealed class $instantinator = function () { return new static; }; $instantinator = $instantinator->bindTo(null, Seal::class); $instance = $instantinator(); var_dump($instance); #3 Via unserialize hack $instance = unserialize(sprintf('O:%d:"%s":0:{}', strlen(Seal::class), Seal::class)); var_dump($instance); #4 Via PDO, requires pdo_sqlite which is typically available, can be pdo_mysql, then change: SELECT "test" FROM DUAL if (phpversion('pdo_sqlite')) { $database = new PDO('sqlite::memory:'); $result = $database->query('SELECT "test" as field1'); // We can even initialize properties in the object $instance = $result->fetchObject(Seal::class); var_dump($instance); } #5 Via STOMP, requires php_stomp to be loaded if (phpversion('stomp')) { $connection = new Stomp(/* connection args */); $connection->subscribe('Test'); $connection->readFrame(Seal::class); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 54
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 67
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
Branch analysis from position: 54
filename:       /in/cSfPS
function name:  (null)
number of ops:  68
compiled vars:  !0 = $refClass, !1 = $instance, !2 = $instantinator, !3 = $database, !4 = $result, !5 = $connection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   NEW                                              $6      'ReflectionClass'
          1        SEND_VAL_EX                                              'Seal'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $6
   15     4        INIT_METHOD_CALL                                         !0, 'newInstanceWithoutConstructor'
          5        DO_FCALL                                      0  $9      
          6        ASSIGN                                                   !1, $9
   16     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   19    10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FcSfPS%3A19%240'
         11        ASSIGN                                                   !2, ~12
   22    12        INIT_METHOD_CALL                                         !2, 'bindTo'
         13        SEND_VAL_EX                                              null
         14        SEND_VAL_EX                                              'Seal'
         15        DO_FCALL                                      0  $14     
         16        ASSIGN                                                   !2, $14
   23    17        INIT_DYNAMIC_CALL                                        !2
         18        DO_FCALL                                      0  $16     
         19        ASSIGN                                                   !1, $16
   24    20        INIT_FCALL                                               'var_dump'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
   27    23        INIT_FCALL                                               'unserialize'
         24        INIT_FCALL                                               'sprintf'
         25        SEND_VAL                                                 'O%3A%25d%3A%22%25s%22%3A0%3A%7B%7D'
         26        SEND_VAL                                                 4
         27        SEND_VAL                                                 'Seal'
         28        DO_ICALL                                         $19     
         29        SEND_VAR                                                 $19
         30        DO_ICALL                                         $20     
         31        ASSIGN                                                   !1, $20
   28    32        INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !1
         34        DO_ICALL                                                 
   31    35        INIT_FCALL                                               'phpversion'
         36        SEND_VAL                                                 'pdo_sqlite'
         37        DO_ICALL                                         $23     
         38      > JMPZ                                                     $23, ->54
   32    39    >   NEW                                              $24     'PDO'
         40        SEND_VAL_EX                                              'sqlite%3A%3Amemory%3A'
         41        DO_FCALL                                      0          
         42        ASSIGN                                                   !3, $24
   33    43        INIT_METHOD_CALL                                         !3, 'query'
         44        SEND_VAL_EX                                              'SELECT+%22test%22+as+field1'
         45        DO_FCALL                                      0  $27     
         46        ASSIGN                                                   !4, $27
   34    47        INIT_METHOD_CALL                                         !4, 'fetchObject'
         48        SEND_VAL_EX                                              'Seal'
         49        DO_FCALL                                      0  $29     
         50        ASSIGN                                                   !1, $29
   35    51        INIT_FCALL                                               'var_dump'
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                                 
   39    54    >   INIT_FCALL                                               'phpversion'
         55        SEND_VAL                                                 'stomp'
         56        DO_ICALL                                         $32     
         57      > JMPZ                                                     $32, ->67
   40    58    >   NEW                                              $33     'Stomp'
         59        DO_FCALL                                      0          
         60        ASSIGN                                                   !5, $33
   41    61        INIT_METHOD_CALL                                         !5, 'subscribe'
         62        SEND_VAL_EX                                              'Test'
         63        DO_FCALL                                      0          
   42    64        INIT_METHOD_CALL                                         !5, 'readFrame'
         65        SEND_VAL_EX                                              'Seal'
         66        DO_FCALL                                      0          
   43    67    > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FcSfPS%3A19%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cSfPS
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                          static              $0      
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   21     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FcSfPS%3A19%240

Class Seal:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cSfPS
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E > > RETURN                                                   null

End of function __construct

End of class Seal.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.73 ms | 948 KiB | 22 Q