3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = function($className) { if (strpos($className, '\\') !== false) { $parts = array_map('strtolower', array_values(explode('\\', $className))); $count = count($parts); $folder = $file = ''; while ($count--) { if ($count >= 1) { $folder .= array_shift($parts) . ($count > 1 ? '/' : ''); } else { $file = array_shift($parts); } } // Not really a great idea if (substr($folder, 0, 3) == 'api') { $folder = str_replace('api', 'controller/api', $folder); } $fileName = ROOT . '/' . $folder . '/' . $file . '.php'; // Reroute \<namespace>\exception.php -> \library\exception.php if ($file == "exception" && $className != 'API\Exception') { $fileName = ROOT . '/library/exception.php'; } if (is_readable($fileName)) { return $fileName; return true; } } return false; }; $b = function($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; return $fileName; }; $tests = [ '\Library\Database::doQuery', '\Vendor\twilio-php\x', '\namespace\package\Class_Name', '\namespace\package_name\Class_Name' ]; echo '<pre>'; foreach ($tests as $test) { echo 'input ', $test, PHP_EOL; echo 'icr: ', $a($test), PHP_EOL; echo 'psr: ', $b($test), PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/BIbEg
function name:  (null)
number of ops:  26
compiled vars:  !0 = $a, !1 = $b, !2 = $tests, !3 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBIbEg%3A3%240'
          1        ASSIGN                                                   !0, ~4
   39     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBIbEg%3A39%241'
          3        ASSIGN                                                   !1, ~6
   54     4        ASSIGN                                                   !2, <array>
   61     5        ECHO                                                     '%3Cpre%3E'
   62     6      > FE_RESET_R                                       $9      !2, ->24
          7    > > FE_FETCH_R                                               $9, !3, ->24
   63     8    >   ECHO                                                     'input+'
          9        ECHO                                                     !3
         10        ECHO                                                     '%0A'
   64    11        ECHO                                                     'icr%3A+'
         12        INIT_DYNAMIC_CALL                                        !0
         13        SEND_VAR_EX                                              !3
         14        DO_FCALL                                      0  $10     
         15        ECHO                                                     $10
         16        ECHO                                                     '%0A'
   65    17        ECHO                                                     'psr%3A+'
         18        INIT_DYNAMIC_CALL                                        !1
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0  $11     
         21        ECHO                                                     $11
         22        ECHO                                                     '%0A'
   62    23      > JMP                                                      ->7
         24    >   FE_FREE                                                  $9
   66    25      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FBIbEg%3A3%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 77
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 24
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 56
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 65, Position 2 = 67
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 71
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 77
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
Branch analysis from position: 67
Branch analysis from position: 56
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 37
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 24
Branch analysis from position: 43
Branch analysis from position: 24
Branch analysis from position: 77
filename:       /in/BIbEg
function name:  {closure}
number of ops:  79
compiled vars:  !0 = $className, !1 = $parts, !2 = $count, !3 = $folder, !4 = $file, !5 = $fileName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'strpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%5C'
          4        DO_ICALL                                         $6      
          5        TYPE_CHECK                                  1018          $6
          6      > JMPZ                                                     ~7, ->77
    5     7    >   INIT_FCALL                                               'array_map'
          8        SEND_VAL                                                 'strtolower'
          9        INIT_FCALL                                               'array_values'
         10        INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '%5C'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $8      
         14        SEND_VAR                                                 $8
         15        DO_ICALL                                         $9      
         16        SEND_VAR                                                 $9
         17        DO_ICALL                                         $10     
         18        ASSIGN                                                   !1, $10
    6    19        COUNT                                            ~12     !1
         20        ASSIGN                                                   !2, ~12
    8    21        ASSIGN                                           ~14     !4, ''
         22        ASSIGN                                                   !3, ~14
   10    23      > JMP                                                      ->41
   11    24    >   IS_SMALLER_OR_EQUAL                                      1, !2
         25      > JMPZ                                                     ~16, ->37
   12    26    >   INIT_FCALL                                               'array_shift'
         27        SEND_REF                                                 !1
         28        DO_ICALL                                         $17     
         29        IS_SMALLER                                               1, !2
         30      > JMPZ                                                     ~18, ->33
         31    >   QM_ASSIGN                                        ~19     '%2F'
         32      > JMP                                                      ->34
         33    >   QM_ASSIGN                                        ~19     ''
         34    >   CONCAT                                           ~20     $17, ~19
         35        ASSIGN_OP                                     8          !3, ~20
         36      > JMP                                                      ->41
   14    37    >   INIT_FCALL                                               'array_shift'
         38        SEND_REF                                                 !1
         39        DO_ICALL                                         $22     
         40        ASSIGN                                                   !4, $22
   10    41    >   POST_DEC                                         ~24     !2
         42      > JMPNZ                                                    ~24, ->24
   19    43    >   INIT_FCALL                                               'substr'
         44        SEND_VAR                                                 !3
         45        SEND_VAL                                                 0
         46        SEND_VAL                                                 3
         47        DO_ICALL                                         $25     
         48        IS_EQUAL                                                 $25, 'api'
         49      > JMPZ                                                     ~26, ->56
   20    50    >   INIT_FCALL                                               'str_replace'
         51        SEND_VAL                                                 'api'
         52        SEND_VAL                                                 'controller%2Fapi'
         53        SEND_VAR                                                 !3
         54        DO_ICALL                                         $27     
         55        ASSIGN                                                   !3, $27
   23    56    >   FETCH_CONSTANT                                   ~29     'ROOT'
         57        CONCAT                                           ~30     ~29, '%2F'
         58        CONCAT                                           ~31     ~30, !3
         59        CONCAT                                           ~32     ~31, '%2F'
         60        CONCAT                                           ~33     ~32, !4
         61        CONCAT                                           ~34     ~33, '.php'
         62        ASSIGN                                                   !5, ~34
   26    63        IS_EQUAL                                         ~36     !4, 'exception'
         64      > JMPZ_EX                                          ~36     ~36, ->67
         65    >   IS_NOT_EQUAL                                     ~37     !0, 'API%5CException'
         66        BOOL                                             ~36     ~37
         67    > > JMPZ                                                     ~36, ->71
   27    68    >   FETCH_CONSTANT                                   ~38     'ROOT'
         69        CONCAT                                           ~39     ~38, '%2Flibrary%2Fexception.php'
         70        ASSIGN                                                   !5, ~39
   30    71    >   INIT_FCALL                                               'is_readable'
         72        SEND_VAR                                                 !5
         73        DO_ICALL                                         $41     
         74      > JMPZ                                                     $41, ->77
   31    75    > > RETURN                                                   !5
   32    76*       RETURN                                                   <true>
   36    77    > > RETURN                                                   <false>
   37    78*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBIbEg%3A3%240

Function %00%7Bclosure%7D%2Fin%2FBIbEg%3A39%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 33
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/BIbEg
function name:  {closure}
number of ops:  42
compiled vars:  !0 = $className, !1 = $fileName, !2 = $namespace, !3 = $lastNsPos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        INIT_FCALL                                               'ltrim'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%5C'
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !0, $4
   41     6        ASSIGN                                                   !1, ''
   42     7        ASSIGN                                                   !2, ''
   43     8        INIT_FCALL                                               'strrpos'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 '%5C'
         11        DO_ICALL                                         $8      
         12        ASSIGN                                           ~9      !3, $8
         13      > JMPZ                                                     ~9, ->33
   44    14    >   INIT_FCALL                                               'substr'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 0
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $10     
         19        ASSIGN                                                   !2, $10
   45    20        INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !0
         22        ADD                                              ~12     !3, 1
         23        SEND_VAL                                                 ~12
         24        DO_ICALL                                         $13     
         25        ASSIGN                                                   !0, $13
   46    26        INIT_FCALL                                               'str_replace'
         27        SEND_VAL                                                 '%5C'
         28        SEND_VAL                                                 '%2F'
         29        SEND_VAR                                                 !2
         30        DO_ICALL                                         $15     
         31        CONCAT                                           ~16     $15, '%2F'
         32        ASSIGN                                                   !1, ~16
   48    33    >   INIT_FCALL                                               'str_replace'
         34        SEND_VAL                                                 '_'
         35        SEND_VAL                                                 '%2F'
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $18     
         38        CONCAT                                           ~19     $18, '.php'
         39        ASSIGN_OP                                     8          !1, ~19
   50    40      > RETURN                                                   !1
   51    41*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBIbEg%3A39%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.31 ms | 1408 KiB | 33 Q