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; } }); $c1 = new \Foo\Bar\Baz(); $c2 = new \Foo\Bar\BAZ(); $c3 = new \Foo\Bar\BUZ(); $c4 = new \Foo\Bar\Buz(); var_dump( $c1 == $c2, $c3 == $c4 );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i3uIM
function name:  (null)
number of ops:  37
compiled vars:  !0 = $base_dir, !1 = $c1, !2 = $c2, !3 = $c3, !4 = $c4
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'sys_get_temp_dir'
          1        DO_ICALL                                         $5      
          2        CONCAT                                           ~6      $5, '%2F'
          3        ASSIGN                                                   !0, ~6
    5     4        INIT_FCALL                                               'file_put_contents'
          5        CONCAT                                           ~8      !0, 'Baz.php'
          6        SEND_VAL                                                 ~8
          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                                           ~10     !0, 'Buz.php'
         11        SEND_VAL                                                 ~10
         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%2Fi3uIM%3A8%240'
   35    16        SEND_VAL                                                 ~12
         17        DO_ICALL                                                 
   37    18        NEW                                              $14     'Foo%5CBar%5CBaz'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !1, $14
   38    21        NEW                                              $17     'Foo%5CBar%5CBAZ'
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !2, $17
   39    24        NEW                                              $20     'Foo%5CBar%5CBUZ'
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !3, $20
   40    27        NEW                                              $23     'Foo%5CBar%5CBuz'
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !4, $23
   42    30        INIT_FCALL                                               'var_dump'
   43    31        IS_EQUAL                                         ~26     !1, !2
         32        SEND_VAL                                                 ~26
   44    33        IS_EQUAL                                         ~27     !3, !4
         34        SEND_VAL                                                 ~27
         35        DO_ICALL                                                 
   45    36      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fi3uIM%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/i3uIM
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%2Fi3uIM%3A8%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.6 ms | 1400 KiB | 29 Q