3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class IntFilter { public static function check(int $value, array $options = array()) { return $value; } } final class StringFilter { public static function check(string $value, array $options = array()) { // Trim if (false !== ($options['trim'] ?? true)) { $value = trim($value); } $length = mb_strlen($value, '8bit'); // Empty if (false === ($options['empty'] ?? true)) { if (0 === $length) { throw new LengthException('chaine vide !'); } } // Min & max length if (isset($options['max'])) { $maxLength = IntFilter::check($options['max'], ['min' => 1]); if ($length > $maxLength) { throw new LengthException('trop long !'); } } if (isset($options['min'])) { $minLength = IntFilter::check($options['min'], ['min' => 1]); if ($length < $minLength) { throw new LengthException('trop court !'); } } if (isset($options['startsWith'])) { $needle = StringFilter::check($options['startsWith']); if (false === self::startsWith($value, $needle)) { throw new InvalidArgumentException('mauvais début !'); } } if (isset($options['endsWith'])) { $needle = StringFilter::check($options['endsWith']); if (false === self::endsWith($value, $needle)) { throw new InvalidArgumentException('mauvaise fin !'); } } return $value; } private static function startsWith($haystack, $needle) { return $haystack[0] === $needle[0] ? strncmp($haystack, $needle, mb_strlen($needle, '8bit')) === 0 : false; } private static function endsWith($haystack, $needle) { $length = mb_strlen($needle, '8bit'); $haystack = mb_substr($haystack, -$length); return $haystack[0] === $needle[0] ? strncmp($haystack, $needle, $length) === 0 : false; } } var_dump(StringFilter::check(' test ', ['endsWith' => 'st']));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZrURb
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_STATIC_METHOD_CALL                                  'StringFilter', 'check'
          2        SEND_VAL                                                 '+++test++++'
          3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Class IntFilter:
Function check:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZrURb
function name:  check
number of ops:  4
compiled vars:  !0 = $value, !1 = $options
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    7     2      > RETURN                                                   !0
    8     3*     > RETURN                                                   null

End of function check

End of class IntFilter.

Class StringFilter:
Function check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 41
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 41
Branch analysis from position: 37
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 55
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 72
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 72
Branch analysis from position: 68
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 89
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 89
Branch analysis from position: 85
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 89
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 89
Branch analysis from position: 72
Branch analysis from position: 55
Branch analysis from position: 41
Branch analysis from position: 27
Branch analysis from position: 11
filename:       /in/ZrURb
function name:  check
number of ops:  91
compiled vars:  !0 = $value, !1 = $options, !2 = $length, !3 = $maxLength, !4 = $minLength, !5 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   16     2        FETCH_DIM_IS                                     ~6      !1, 'trim'
          3        COALESCE                                         ~7      ~6
          4        QM_ASSIGN                                        ~7      <true>
          5        TYPE_CHECK                                  1018          ~7
          6      > JMPZ                                                     ~8, ->11
   17     7    >   INIT_FCALL                                               'trim'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !0, $9
   20    11    >   INIT_FCALL                                               'mb_strlen'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 '8bit'
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !2, $11
   23    16        FETCH_DIM_IS                                     ~13     !1, 'empty'
         17        COALESCE                                         ~14     ~13
         18        QM_ASSIGN                                        ~14     <true>
         19        TYPE_CHECK                                    4          ~14
         20      > JMPZ                                                     ~15, ->27
   24    21    >   IS_IDENTICAL                                             !2, 0
         22      > JMPZ                                                     ~16, ->27
   25    23    >   NEW                                              $17     'LengthException'
         24        SEND_VAL_EX                                              'chaine+vide+%21'
         25        DO_FCALL                                      0          
         26      > THROW                                         0          $17
   30    27    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'max'
         28      > JMPZ                                                     ~19, ->41
   31    29    >   INIT_STATIC_METHOD_CALL                                  'IntFilter', 'check'
         30        FETCH_DIM_R                                      ~20     !1, 'max'
         31        SEND_VAL                                                 ~20
         32        SEND_VAL                                                 <array>
         33        DO_FCALL                                      0  $21     
         34        ASSIGN                                                   !3, $21
   33    35        IS_SMALLER                                               !3, !2
         36      > JMPZ                                                     ~23, ->41
   34    37    >   NEW                                              $24     'LengthException'
         38        SEND_VAL_EX                                              'trop+long+%21'
         39        DO_FCALL                                      0          
         40      > THROW                                         0          $24
   38    41    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'min'
         42      > JMPZ                                                     ~26, ->55
   39    43    >   INIT_STATIC_METHOD_CALL                                  'IntFilter', 'check'
         44        FETCH_DIM_R                                      ~27     !1, 'min'
         45        SEND_VAL                                                 ~27
         46        SEND_VAL                                                 <array>
         47        DO_FCALL                                      0  $28     
         48        ASSIGN                                                   !4, $28
   41    49        IS_SMALLER                                               !2, !4
         50      > JMPZ                                                     ~30, ->55
   42    51    >   NEW                                              $31     'LengthException'
         52        SEND_VAL_EX                                              'trop+court+%21'
         53        DO_FCALL                                      0          
         54      > THROW                                         0          $31
   46    55    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'startsWith'
         56      > JMPZ                                                     ~33, ->72
   47    57    >   INIT_STATIC_METHOD_CALL                                  'StringFilter', 'check'
         58        FETCH_DIM_R                                      ~34     !1, 'startsWith'
         59        SEND_VAL                                                 ~34
         60        DO_FCALL                                      0  $35     
         61        ASSIGN                                                   !5, $35
   49    62        INIT_STATIC_METHOD_CALL                                  'startsWith'
         63        SEND_VAR_EX                                              !0
         64        SEND_VAR_EX                                              !5
         65        DO_FCALL                                      0  $37     
         66        TYPE_CHECK                                    4          $37
         67      > JMPZ                                                     ~38, ->72
   50    68    >   NEW                                              $39     'InvalidArgumentException'
         69        SEND_VAL_EX                                              'mauvais+d%C3%A9but+%21'
         70        DO_FCALL                                      0          
         71      > THROW                                         0          $39
   54    72    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'endsWith'
         73      > JMPZ                                                     ~41, ->89
   55    74    >   INIT_STATIC_METHOD_CALL                                  'StringFilter', 'check'
         75        FETCH_DIM_R                                      ~42     !1, 'endsWith'
         76        SEND_VAL                                                 ~42
         77        DO_FCALL                                      0  $43     
         78        ASSIGN                                                   !5, $43
   57    79        INIT_STATIC_METHOD_CALL                                  'endsWith'
         80        SEND_VAR_EX                                              !0
         81        SEND_VAR_EX                                              !5
         82        DO_FCALL                                      0  $45     
         83        TYPE_CHECK                                    4          $45
         84      > JMPZ                                                     ~46, ->89
   58    85    >   NEW                                              $47     'InvalidArgumentException'
         86        SEND_VAL_EX                                              'mauvaise+fin+%21'
         87        DO_FCALL                                      0          
         88      > THROW                                         0          $47
   62    89    > > RETURN                                                   !0
   63    90*     > RETURN                                                   null

End of function check

Function startswith:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZrURb
function name:  startsWith
number of ops:  21
compiled vars:  !0 = $haystack, !1 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   67     2        FETCH_DIM_R                                      ~2      !0, 0
          3        FETCH_DIM_R                                      ~3      !1, 0
          4        IS_IDENTICAL                                             ~2, ~3
          5      > JMPZ                                                     ~4, ->18
          6    >   INIT_FCALL                                               'strncmp'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        INIT_FCALL                                               'mb_strlen'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 '8bit'
         12        DO_ICALL                                         $5      
         13        SEND_VAR                                                 $5
         14        DO_ICALL                                         $6      
         15        IS_IDENTICAL                                     ~7      $6, 0
         16        QM_ASSIGN                                        ~8      ~7
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~8      <false>
         19    > > RETURN                                                   ~8
   68    20*     > RETURN                                                   null

End of function startswith

Function endswith:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 25
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZrURb
function name:  endsWith
number of ops:  28
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   72     2        INIT_FCALL                                               'mb_strlen'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 '8bit'
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
   73     7        INIT_FCALL                                               'mb_substr'
          8        SEND_VAR                                                 !0
          9        MUL                                              ~5      !2, -1
         10        SEND_VAL                                                 ~5
         11        DO_ICALL                                         $6      
         12        ASSIGN                                                   !0, $6
   75    13        FETCH_DIM_R                                      ~8      !0, 0
         14        FETCH_DIM_R                                      ~9      !1, 0
         15        IS_IDENTICAL                                             ~8, ~9
         16      > JMPZ                                                     ~10, ->25
         17    >   INIT_FCALL                                               'strncmp'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !1
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                         $11     
         22        IS_IDENTICAL                                     ~12     $11, 0
         23        QM_ASSIGN                                        ~13     ~12
         24      > JMP                                                      ->26
         25    >   QM_ASSIGN                                        ~13     <false>
         26    > > RETURN                                                   ~13
   76    27*     > RETURN                                                   null

End of function endswith

End of class StringFilter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.32 ms | 1412 KiB | 23 Q