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 {}"); 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());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e3NDs
function name:  (null)
number of ops:  24
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                                                 
    7     9        INIT_FCALL                                               'spl_autoload_register'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fe3NDs%3A7%240'
   34    11        SEND_VAL                                                 ~6
         12        DO_ICALL                                                 
   36    13        INIT_FCALL                                               'var_dump'
         14        NEW                                              $8      'Foo%5CBar%5CBAZ'
         15        DO_FCALL                                      0          
         16        SEND_VAR                                                 $8
         17        DO_ICALL                                                 
   37    18        INIT_FCALL                                               'var_dump'
         19        NEW                                              $11     'Foo%5CBar%5Cbaz'
         20        DO_FCALL                                      0          
         21        SEND_VAR                                                 $11
         22        DO_ICALL                                                 
         23      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fe3NDs%3A7%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/e3NDs
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
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
   10     1        ASSIGN                                                   !1, 'Foo%5CBar%5C'
   13     2        BIND_GLOBAL                                              !2, 'base_dir'
   16     3        STRLEN                                           ~7      !1
          4        ASSIGN                                                   !3, ~7
   17     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
   19    12    > > RETURN                                                   null
   23    13    >   INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $11     
         17        ASSIGN                                                   !4, $11
   28    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
   31    26        INIT_FCALL                                               'file_exists'
         27        SEND_VAR                                                 !5
         28        DO_ICALL                                         $17     
         29      > JMPZ                                                     $17, ->31
   32    30    >   INCLUDE_OR_EVAL                                          !5, REQUIRE
   34    31    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fe3NDs%3A7%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.03 ms | 1400 KiB | 29 Q