3v4l.org

run code in 300+ PHP versions simultaneously
<?php $base_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR; file_put_contents($base_dir . 'Baz.php', "<?php namespace Foo\Bar; class Baz {}"); file_put_contents($base_dir . 'Buz.php', "<?php namespace Foo\Bar; class Buz {}"); spl_autoload_register(function ($class) { // project-specific namespace prefix $prefix = 'Foo\\Bar\\'; // base directory for the namespace prefix global $base_dir; // does the class use the namespace prefix? $len = strlen($prefix); if (strncmp($prefix, $class, $len) !== 0) { // no, move to the next registered autoloader return; } // get the relative class name $relative_class = substr($class, $len); // replace the namespace prefix with the base directory, replace namespace // separators with directory separators in the relative class name, append // with .php $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; // if the file exists, require it if (file_exists($file)) { require $file; } }); var_dump(new \Foo\Bar\Baz()); var_dump(new \Foo\Bar\BAZ()); var_dump(new \Foo\Bar\BUZ()); var_dump(new \Foo\Bar\Buz());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mSKeT
function name:  (null)
number of ops:  39
compiled vars:  !0 = $base_dir
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'sys_get_temp_dir'
          1        DO_ICALL                                         $1      
          2        CONCAT                                           ~2      $1, '%2F'
          3        ASSIGN                                                   !0, ~2
    5     4        INIT_FCALL                                               'file_put_contents'
          5        CONCAT                                           ~4      !0, 'Baz.php'
          6        SEND_VAL                                                 ~4
          7        SEND_VAL                                                 '%3C%3Fphp+namespace+Foo%5CBar%3B+class+Baz+%7B%7D'
          8        DO_ICALL                                                 
    6     9        INIT_FCALL                                               'file_put_contents'
         10        CONCAT                                           ~6      !0, 'Buz.php'
         11        SEND_VAL                                                 ~6
         12        SEND_VAL                                                 '%3C%3Fphp+namespace+Foo%5CBar%3B+class+Buz+%7B%7D'
         13        DO_ICALL                                                 
    8    14        INIT_FCALL                                               'spl_autoload_register'
         15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FmSKeT%3A8%240'
   35    16        SEND_VAL                                                 ~8
         17        DO_ICALL                                                 
   37    18        INIT_FCALL                                               'var_dump'
         19        NEW                                              $10     'Foo%5CBar%5CBaz'
         20        DO_FCALL                                      0          
         21        SEND_VAR                                                 $10
         22        DO_ICALL                                                 
   38    23        INIT_FCALL                                               'var_dump'
         24        NEW                                              $13     'Foo%5CBar%5CBAZ'
         25        DO_FCALL                                      0          
         26        SEND_VAR                                                 $13
         27        DO_ICALL                                                 
   40    28        INIT_FCALL                                               'var_dump'
         29        NEW                                              $16     'Foo%5CBar%5CBUZ'
         30        DO_FCALL                                      0          
         31        SEND_VAR                                                 $16
         32        DO_ICALL                                                 
   41    33        INIT_FCALL                                               'var_dump'
         34        NEW                                              $19     'Foo%5CBar%5CBuz'
         35        DO_FCALL                                      0          
         36        SEND_VAR                                                 $19
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FmSKeT%3A8%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/mSKeT
function name:  {closure}
number of ops:  32
compiled vars:  !0 = $class, !1 = $prefix, !2 = $base_dir, !3 = $len, !4 = $relative_class, !5 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   11     1        ASSIGN                                                   !1, 'Foo%5CBar%5C'
   14     2        BIND_GLOBAL                                              !2, 'base_dir'
   17     3        STRLEN                                           ~7      !1
          4        ASSIGN                                                   !3, ~7
   18     5        INIT_FCALL                                               'strncmp'
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $9      
         10        IS_NOT_IDENTICAL                                         $9, 0
         11      > JMPZ                                                     ~10, ->13
   20    12    > > RETURN                                                   null
   24    13    >   INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $11     
         17        ASSIGN                                                   !4, $11
   29    18        INIT_FCALL                                               'str_replace'
         19        SEND_VAL                                                 '%5C'
         20        SEND_VAL                                                 '%2F'
         21        SEND_VAR                                                 !4
         22        DO_ICALL                                         $13     
         23        CONCAT                                           ~14     !2, $13
         24        CONCAT                                           ~15     ~14, '.php'
         25        ASSIGN                                                   !5, ~15
   32    26        INIT_FCALL                                               'file_exists'
         27        SEND_VAR                                                 !5
         28        DO_ICALL                                         $17     
         29      > JMPZ                                                     $17, ->31
   33    30    >   INCLUDE_OR_EVAL                                          !5, REQUIRE
   35    31    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FmSKeT%3A8%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.18 ms | 1400 KiB | 29 Q