3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Length { public $violations = []; /** * Minimum length. * * @var int */ private $min; /** * Maximum length. * * @var int */ private $max; /** * Charset. * * @var string */ private $charset; /** * Length validation rule constructor. * * @param int $min * @param int $max * @param string $charset * @throws InvalidArgumentException * @throws LogicException */ public function __construct( $min = null, $max = null, $charset = 'UTF-8' ) { if ($min === null && $max === null) { throw new \InvalidArgumentException('Either option "min" or "max" must be given.'); } if ($max < $min) { throw new \LogicException('"Max" option cannot be less that "min".'); } $this->min = $min; $this->max = $max; $this->charset = $charset; } /** * Validates input. * * @param mixed $input * * @return bool */ public function isValid($input = null) { if ($input === null || $input === '') { return false; } $input = (string) $input; if (!$invalidCharset = !@mb_check_encoding($input, $this->charset)) { $length = mb_strlen($input, $this->charset); } if ($invalidCharset) { $this->violations[] = 'charset'; return false; } if ($this->max !== null && $length > $this->max) { $this->violations[] = 'max'; return false; } if ($this->min !== null && $length < $this->min) { $this->violations[] = 'min'; return false; } return true; } } $length = new Length(-100, ['a', 'b', 'c', 185, null]); $length->isValid(stream_context_create()); echo sprintf('Count fail violations: %d', count($length->violations));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CnePS
function name:  (null)
number of ops:  18
compiled vars:  !0 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   NEW                                              $1      'Length'
          1        SEND_VAL_EX                                              -100
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   82     5        INIT_METHOD_CALL                                         !0, 'isValid'
          6        INIT_FCALL                                               'stream_context_create'
          7        DO_ICALL                                         $4      
          8        SEND_VAR_NO_REF_EX                                       $4
          9        DO_FCALL                                      0          
   84    10        INIT_FCALL                                               'sprintf'
         11        SEND_VAL                                                 'Count+fail+violations%3A+%25d'
         12        FETCH_OBJ_R                                      ~6      !0, 'violations'
         13        COUNT                                            ~7      ~6
         14        SEND_VAL                                                 ~7
         15        DO_ICALL                                         $8      
         16        ECHO                                                     $8
         17      > RETURN                                                   1

Class Length:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/CnePS
function name:  __construct
number of ops:  25
compiled vars:  !0 = $min, !1 = $max, !2 = $charset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      'UTF-8'
   39     3        TYPE_CHECK                                    2  ~3      !0
          4      > JMPZ_EX                                          ~3      ~3, ->7
          5    >   TYPE_CHECK                                    2  ~4      !1
          6        BOOL                                             ~3      ~4
          7    > > JMPZ                                                     ~3, ->12
   40     8    >   NEW                                              $5      'InvalidArgumentException'
          9        SEND_VAL_EX                                              'Either+option+%22min%22+or+%22max%22+must+be+given.'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $5
   42    12    >   IS_SMALLER                                               !1, !0
         13      > JMPZ                                                     ~7, ->18
   43    14    >   NEW                                              $8      'LogicException'
         15        SEND_VAL_EX                                              '%22Max%22+option+cannot+be+less+that+%22min%22.'
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $8
   45    18    >   ASSIGN_OBJ                                               'min'
         19        OP_DATA                                                  !0
   46    20        ASSIGN_OBJ                                               'max'
         21        OP_DATA                                                  !1
   47    22        ASSIGN_OBJ                                               'charset'
         23        OP_DATA                                                  !2
   48    24      > RETURN                                                   null

End of function __construct

Function isvalid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 42
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
Branch analysis from position: 37
Branch analysis from position: 26
Branch analysis from position: 5
filename:       /in/CnePS
function name:  isValid
number of ops:  55
compiled vars:  !0 = $input, !1 = $invalidCharset, !2 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV_INIT                                        !0      null
   58     1        TYPE_CHECK                                    2  ~3      !0
          2      > JMPNZ_EX                                         ~3      ~3, ->5
          3    >   IS_IDENTICAL                                     ~4      !0, ''
          4        BOOL                                             ~3      ~4
          5    > > JMPZ                                                     ~3, ->7
   59     6    > > RETURN                                                   <false>
   61     7    >   CAST                                          6  ~5      !0
          8        ASSIGN                                                   !0, ~5
   62     9        BEGIN_SILENCE                                    ~7      
         10        INIT_FCALL                                               'mb_check_encoding'
         11        SEND_VAR                                                 !0
         12        FETCH_OBJ_R                                      ~8      'charset'
         13        SEND_VAL                                                 ~8
         14        DO_ICALL                                         $9      
         15        END_SILENCE                                              ~7
         16        BOOL_NOT                                         ~10     $9
         17        ASSIGN                                           ~11     !1, ~10
         18        BOOL_NOT                                         ~12     ~11
         19      > JMPZ                                                     ~12, ->26
   63    20    >   INIT_FCALL                                               'mb_strlen'
         21        SEND_VAR                                                 !0
         22        FETCH_OBJ_R                                      ~13     'charset'
         23        SEND_VAL                                                 ~13
         24        DO_ICALL                                         $14     
         25        ASSIGN                                                   !2, $14
   65    26    > > JMPZ                                                     !1, ->31
   66    27    >   FETCH_OBJ_W                                      $16     'violations'
         28        ASSIGN_DIM                                               $16
         29        OP_DATA                                                  'charset'
   67    30      > RETURN                                                   <false>
   69    31    >   FETCH_OBJ_R                                      ~18     'max'
         32        TYPE_CHECK                                  1020  ~19     ~18
         33      > JMPZ_EX                                          ~19     ~19, ->37
         34    >   FETCH_OBJ_R                                      ~20     'max'
         35        IS_SMALLER                                       ~21     ~20, !2
         36        BOOL                                             ~19     ~21
         37    > > JMPZ                                                     ~19, ->42
   70    38    >   FETCH_OBJ_W                                      $22     'violations'
         39        ASSIGN_DIM                                               $22
         40        OP_DATA                                                  'max'
   71    41      > RETURN                                                   <false>
   73    42    >   FETCH_OBJ_R                                      ~24     'min'
         43        TYPE_CHECK                                  1020  ~25     ~24
         44      > JMPZ_EX                                          ~25     ~25, ->48
         45    >   FETCH_OBJ_R                                      ~26     'min'
         46        IS_SMALLER                                       ~27     !2, ~26
         47        BOOL                                             ~25     ~27
         48    > > JMPZ                                                     ~25, ->53
   74    49    >   FETCH_OBJ_W                                      $28     'violations'
         50        ASSIGN_DIM                                               $28
         51        OP_DATA                                                  'min'
   75    52      > RETURN                                                   <false>
   77    53    > > RETURN                                                   <true>
   78    54*     > RETURN                                                   null

End of function isvalid

End of class Length.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.11 ms | 1404 KiB | 21 Q