3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Filter { abstract public static function check($value, array $options = array()); } final class IntFilter { public static function check($value, array $options = array()) { return $value; } } final class StringFilter { public static function check($value, array $options = array()) { if (false === is_string($value)) { return false; } if (false !== ($options['trim'] ?? true)) { $value = trim($value); } $length = mb_strlen($value, '8bit'); if ((false === ($options['empty'] ?? true)) && (0 === $length)) { return false; } if (isset($options['max'])) { $maxLength = IntFilter::check($options['max'], ['min' => 1]); if ($length > $maxLength) { return false; } } if (isset($options['min'])) { $minLength = IntFilter::check($options['min'], ['min' => 1]); if ($length < $minLength) { return false; } } if (isset($options['startsWith'])) { $needle = StringFilter::check($options['startsWith']); if (false === self::startsWith($value, $needle)) { return false; } } if (isset($options['endsWith'])) { $needle = StringFilter::check($options['endsWith']); if (false === self::endsWith($value, $needle)) { return false; } } 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(' r a ', ['empty' => false]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SFoK6
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_STATIC_METHOD_CALL                                  'StringFilter', 'check'
          2        SEND_VAL                                                 '++r++a+++'
          3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Class Filter:
Function check:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SFoK6
function name:  check
number of ops:  3
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>
          2      > RETURN                                                   null

End of function check

End of class Filter.

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

End of function endswith

End of class StringFilter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.85 ms | 1412 KiB | 23 Q