3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Twig { const TWIG_PREFIX = 1; const SHORT = 2; public static function getMode(string $input): int { $mode = 0; if (str_contains($input, '<twig:')) { $mode |= Twig::TWIG_PREFIX; } if (preg_match_all('/<([A-Z][a-zA-Z0-9_:-]+)([^>]*)>/', $input, $matches, \PREG_SET_ORDER)) { $mode |= Twig::SHORT; } return $mode; } } // Both $input = '<twig:test></twig:test> <Test>test</Test>'; $mode = Twig::getMode($input); var_dump($mode); $hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX); $hasShort = (bool) ($mode & Twig::SHORT); var_dump($hasTwigPrefix); var_dump($hasShort); // Twig $input = '<twig:test></twig:test>'; $mode = Twig::getMode($input); var_dump($mode); $hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX); $hasShort = (bool) ($mode & Twig::SHORT); var_dump($hasTwigPrefix); var_dump($hasShort); // Short $input = '<Test>test</Test>'; $mode = Twig::getMode($input); var_dump($mode); $hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX); $hasShort = (bool) ($mode & Twig::SHORT); var_dump($hasTwigPrefix); var_dump($hasShort); // Nothing $input = '<section>test</section>'; $mode = Twig::getMode($input); var_dump($mode); $hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX); $hasShort = (bool) ($mode & Twig::SHORT); var_dump($hasTwigPrefix); var_dump($hasShort);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Wln8L
function name:  (null)
number of ops:  81
compiled vars:  !0 = $input, !1 = $mode, !2 = $hasTwigPrefix, !3 = $hasShort
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, '%3Ctwig%3Atest%3E%3C%2Ftwig%3Atest%3E+%3CTest%3Etest%3C%2FTest%3E'
   26     1        INIT_STATIC_METHOD_CALL                                  'Twig', 'getMode'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $5      
          4        ASSIGN                                                   !1, $5
   27     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
   28     8        BW_AND                                           ~8      !1, 1
          9        BOOL                                             ~9      ~8
         10        ASSIGN                                                   !2, ~9
   29    11        BW_AND                                           ~11     !1, 2
         12        BOOL                                             ~12     ~11
         13        ASSIGN                                                   !3, ~12
   30    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                                 
   31    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                                 
   34    20        ASSIGN                                                   !0, '%3Ctwig%3Atest%3E%3C%2Ftwig%3Atest%3E'
   35    21        INIT_STATIC_METHOD_CALL                                  'Twig', 'getMode'
         22        SEND_VAR                                                 !0
         23        DO_FCALL                                      0  $17     
         24        ASSIGN                                                   !1, $17
   36    25        INIT_FCALL                                               'var_dump'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                                 
   37    28        BW_AND                                           ~20     !1, 1
         29        BOOL                                             ~21     ~20
         30        ASSIGN                                                   !2, ~21
   38    31        BW_AND                                           ~23     !1, 2
         32        BOOL                                             ~24     ~23
         33        ASSIGN                                                   !3, ~24
   39    34        INIT_FCALL                                               'var_dump'
         35        SEND_VAR                                                 !2
         36        DO_ICALL                                                 
   40    37        INIT_FCALL                                               'var_dump'
         38        SEND_VAR                                                 !3
         39        DO_ICALL                                                 
   43    40        ASSIGN                                                   !0, '%3CTest%3Etest%3C%2FTest%3E'
   44    41        INIT_STATIC_METHOD_CALL                                  'Twig', 'getMode'
         42        SEND_VAR                                                 !0
         43        DO_FCALL                                      0  $29     
         44        ASSIGN                                                   !1, $29
   45    45        INIT_FCALL                                               'var_dump'
         46        SEND_VAR                                                 !1
         47        DO_ICALL                                                 
   46    48        BW_AND                                           ~32     !1, 1
         49        BOOL                                             ~33     ~32
         50        ASSIGN                                                   !2, ~33
   47    51        BW_AND                                           ~35     !1, 2
         52        BOOL                                             ~36     ~35
         53        ASSIGN                                                   !3, ~36
   48    54        INIT_FCALL                                               'var_dump'
         55        SEND_VAR                                                 !2
         56        DO_ICALL                                                 
   49    57        INIT_FCALL                                               'var_dump'
         58        SEND_VAR                                                 !3
         59        DO_ICALL                                                 
   52    60        ASSIGN                                                   !0, '%3Csection%3Etest%3C%2Fsection%3E'
   53    61        INIT_STATIC_METHOD_CALL                                  'Twig', 'getMode'
         62        SEND_VAR                                                 !0
         63        DO_FCALL                                      0  $41     
         64        ASSIGN                                                   !1, $41
   54    65        INIT_FCALL                                               'var_dump'
         66        SEND_VAR                                                 !1
         67        DO_ICALL                                                 
   55    68        BW_AND                                           ~44     !1, 1
         69        BOOL                                             ~45     ~44
         70        ASSIGN                                                   !2, ~45
   56    71        BW_AND                                           ~47     !1, 2
         72        BOOL                                             ~48     ~47
         73        ASSIGN                                                   !3, ~48
   57    74        INIT_FCALL                                               'var_dump'
         75        SEND_VAR                                                 !2
         76        DO_ICALL                                                 
   58    77        INIT_FCALL                                               'var_dump'
         78        SEND_VAR                                                 !3
         79        DO_ICALL                                                 
         80      > RETURN                                                   1

Class Twig:
Function getmode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 8
filename:       /in/Wln8L
function name:  getMode
number of ops:  20
compiled vars:  !0 = $input, !1 = $mode, !2 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        ASSIGN                                                   !1, 0
   12     2        INIT_FCALL                                               'str_contains'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '%3Ctwig%3A'
          5        DO_ICALL                                         $4      
          6      > JMPZ                                                     $4, ->8
   13     7    >   ASSIGN_OP                                     9          !1, 1
   16     8    >   INIT_FCALL                                               'preg_match_all'
          9        SEND_VAL                                                 '%2F%3C%28%5BA-Z%5D%5Ba-zA-Z0-9_%3A-%5D%2B%29%28%5B%5E%3E%5D%2A%29%3E%2F'
         10        SEND_VAR                                                 !0
         11        SEND_REF                                                 !2
         12        SEND_VAL                                                 2
         13        DO_ICALL                                         $6      
         14      > JMPZ                                                     $6, ->16
   17    15    >   ASSIGN_OP                                     9          !1, 2
   20    16    >   VERIFY_RETURN_TYPE                                       !1
         17      > RETURN                                                   !1
   21    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function getmode

End of class Twig.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.74 ms | 1009 KiB | 16 Q