3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findBase(string $t): string|null { $matches = []; preg_match('/(?P<name>\.([^\.])*)$/', $t, $matches); if (!isset($matches['name'])) { return $t; }; return substr($t, 0, -1 * strlen($matches['name'])); } var_dump(findBase('')); var_dump(findBase('foo')); var_dump(findBase('foo.bar')); var_dump(findBase('foo.bar.baz')); var_dump(findBase('foo.bar[0].baz'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yeg0m
function name:  (null)
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'findbase'
          2        SEND_VAL                                                 ''
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   16     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'findbase'
          8        SEND_VAL                                                 'foo'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   17    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'findbase'
         14        SEND_VAL                                                 'foo.bar'
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                                 
   18    18        INIT_FCALL                                               'var_dump'
         19        INIT_FCALL                                               'findbase'
         20        SEND_VAL                                                 'foo.bar.baz'
         21        DO_FCALL                                      0  $6      
         22        SEND_VAR                                                 $6
         23        DO_ICALL                                                 
   19    24        INIT_FCALL                                               'var_dump'
         25        INIT_FCALL                                               'findbase'
         26        SEND_VAL                                                 'foo.bar%5B0%5D.baz'
         27        DO_FCALL                                      0  $8      
         28        SEND_VAR                                                 $8
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Function findbase:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yeg0m
function name:  findBase
number of ops:  24
compiled vars:  !0 = $t, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    6     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAL                                                 '%2F%28%3FP%3Cname%3E%5C.%28%5B%5E%5C.%5D%29%2A%29%24%2F'
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !1
          6        DO_ICALL                                                 
    8     7        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      !1, 'name'
          8        BOOL_NOT                                         ~5      ~4
          9      > JMPZ                                                     ~5, ->12
    9    10    >   VERIFY_RETURN_TYPE                                       !0
         11      > RETURN                                                   !0
   12    12    >   INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 0
         15        FETCH_DIM_R                                      ~6      !1, 'name'
         16        STRLEN                                           ~7      ~6
         17        MUL                                              ~8      ~7, -1
         18        SEND_VAL                                                 ~8
         19        DO_ICALL                                         $9      
         20        VERIFY_RETURN_TYPE                                       $9
         21      > RETURN                                                   $9
   13    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function findbase

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.81 ms | 1436 KiB | 21 Q