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; } } foreach (['startsWith', 'endsWith'] as $name) { if (isset($options[$name])) { $needle = StringFilter::check($options[$name]); if (false === self::$name($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 ', ['startsWith' => 'r'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'a'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'z']));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HQL9r
function name:  (null)
number of ops:  29
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     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                                                 
   78     7        INIT_FCALL                                               'var_dump'
          8        INIT_STATIC_METHOD_CALL                                  'StringFilter', 'check'
          9        SEND_VAL                                                 '++r++a+++'
         10        SEND_VAL                                                 <array>
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   79    14        INIT_FCALL                                               'var_dump'
         15        INIT_STATIC_METHOD_CALL                                  'StringFilter', 'check'
         16        SEND_VAL                                                 '++r++a+++'
         17        SEND_VAL                                                 <array>
         18        DO_FCALL                                      0  $4      
         19        SEND_VAR                                                 $4
         20        DO_ICALL                                                 
   80    21        INIT_FCALL                                               'var_dump'
         22        INIT_STATIC_METHOD_CALL                                  'StringFilter', 'check'
         23        SEND_VAL                                                 '++r++a+++'
         24        SEND_VAL                                                 <array>
         25        DO_FCALL                                      0  $6      
         26        SEND_VAR                                                 $6
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

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

End of function endswith

End of class StringFilter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
269.41 ms | 1412 KiB | 24 Q