3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_dump(php_uname('s')); $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) { echo "Trying to autoload $class\n"; // project-specific namespace prefix $prefix = 'Foo\\Bar\\'; // base directory for the namespace prefix global $base_dir; # = __DIR__ . '/src/'; // 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; } else { echo "Could not require $file\n"; } }); // This works as expected because the class name matches the intended // case in the file and as it is represented on disk. $c1 = new \Foo\Bar\Baz(); // This works because PHP is PHP. This is not even going to hit the // PSR-4 autoloader. The *usage* of this classname by the user is not // PSR-4 compliant but that does not make the *autoloader* noncompliant. $c2 = new \Foo\Bar\BAZ(); var_dump($c1 == $c2); // This is going to be rejected by the PSR-4 autoloader implementation. // That is fine *and expected* because the *usage* of the classname by // the user is incorrect. // // On some platforms this may actually work but that is a byproduct of // certain platforms not caring about case. But again, the *usage* of // this classname *in this context* is not PSR-4 compliant. // // PSR-4 says that case is important and that case MUST be taken into // account when creating the file path representing the class name. It // also dictates that case MUST be taken into account when you create // files on disk for the FQCN in question. // // If the FQCN is \Foo\Bar\Baz in src/Baz.php, then specifying the class // with any other case than \Foo\Bar\Baz by the user is not compliant // with PSR-4. // // In some cases the planets will align and allow this to work anyway. // If you rely on and promote this, you are actively noncompliant with // PSR-4. $c3 = new \Foo\Bar\BUZ(); $c4 = new \Foo\Bar\Buz(); var_dump($c3 == $c4);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kssKp
function name:  (null)
number of ops:  45
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                                               'var_dump'
          1        INIT_FCALL                                               'php_uname'
          2        SEND_VAL                                                 's'
          3        DO_ICALL                                         $5      
          4        SEND_VAR                                                 $5
          5        DO_ICALL                                                 
    5     6        INIT_FCALL                                               'sys_get_temp_dir'
          7        DO_ICALL                                         $7      
          8        CONCAT                                           ~8      $7, '%2F'
          9        ASSIGN                                                   !0, ~8
    7    10        INIT_FCALL                                               'file_put_contents'
         11        CONCAT                                           ~10     !0, 'Baz.php'
         12        SEND_VAL                                                 ~10
         13        SEND_VAL                                                 '%3C%3Fphp+namespace+Foo%5CBar%3B+class+BAZ+%7B%7D'
         14        DO_ICALL                                                 
    8    15        INIT_FCALL                                               'file_put_contents'
         16        CONCAT                                           ~12     !0, 'Buz.php'
         17        SEND_VAL                                                 ~12
         18        SEND_VAL                                                 '%3C%3Fphp+namespace+Foo%5CBar%3B+class+Buz+%7B%7D'
         19        DO_ICALL                                                 
   10    20        INIT_FCALL                                               'spl_autoload_register'
         21        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FkssKp%3A10%240'
   41    22        SEND_VAL                                                 ~14
         23        DO_ICALL                                                 
   45    24        NEW                                              $16     'Foo%5CBar%5CBaz'
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !1, $16
   50    27        NEW                                              $19     'Foo%5CBar%5CBAZ'
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !2, $19
   52    30        INIT_FCALL                                               'var_dump'
         31        IS_EQUAL                                         ~22     !1, !2
         32        SEND_VAL                                                 ~22
         33        DO_ICALL                                                 
   74    34        NEW                                              $24     'Foo%5CBar%5CBUZ'
         35        DO_FCALL                                      0          
         36        ASSIGN                                                   !3, $24
   75    37        NEW                                              $27     'Foo%5CBar%5CBuz'
         38        DO_FCALL                                      0          
         39        ASSIGN                                                   !4, $27
   77    40        INIT_FCALL                                               'var_dump'
         41        IS_EQUAL                                         ~30     !3, !4
         42        SEND_VAL                                                 ~30
         43        DO_ICALL                                                 
         44      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FkssKp%3A10%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kssKp
function name:  {closure}
number of ops:  41
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
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        ROPE_INIT                                     3  ~7      'Trying+to+autoload+'
          2        ROPE_ADD                                      1  ~7      ~7, !0
          3        ROPE_END                                      2  ~6      ~7, '%0A'
          4        ECHO                                                     ~6
   15     5        ASSIGN                                                   !1, 'Foo%5CBar%5C'
   18     6        BIND_GLOBAL                                              !2, 'base_dir'
   21     7        STRLEN                                           ~10     !1
          8        ASSIGN                                                   !3, ~10
   22     9        INIT_FCALL                                               'strncmp'
         10        SEND_VAR                                                 !1
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $12     
         14        IS_NOT_IDENTICAL                                         $12, 0
         15      > JMPZ                                                     ~13, ->17
   24    16    > > RETURN                                                   null
   28    17    >   INIT_FCALL                                               'substr'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $14     
         21        ASSIGN                                                   !4, $14
   33    22        INIT_FCALL                                               'str_replace'
         23        SEND_VAL                                                 '%5C'
         24        SEND_VAL                                                 '%2F'
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                         $16     
         27        CONCAT                                           ~17     !2, $16
         28        CONCAT                                           ~18     ~17, '.php'
         29        ASSIGN                                                   !5, ~18
   36    30        INIT_FCALL                                               'file_exists'
         31        SEND_VAR                                                 !5
         32        DO_ICALL                                         $20     
         33      > JMPZ                                                     $20, ->36
   37    34    >   INCLUDE_OR_EVAL                                          !5, REQUIRE
         35      > JMP                                                      ->40
   39    36    >   ROPE_INIT                                     3  ~23     'Could+not+require+'
         37        ROPE_ADD                                      1  ~23     ~23, !5
         38        ROPE_END                                      2  ~22     ~23, '%0A'
         39        ECHO                                                     ~22
   41    40    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FkssKp%3A10%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.16 ms | 1404 KiB | 31 Q