3v4l.org

run code in 500+ PHP versions simultaneously
<?php abstract class Constraint { public function __construct(array $options = null) { $defaultOptions = $this->getDefaultOptions(); foreach ($this as $option => $value) { if (isset($defaultOptions[$option])) { $this->{$option} = $defaultOptions[$option]; } else { throw new Exception('Ошибочка'); } } if (null !== $options) { $vars = get_object_vars($this); foreach ($options as $option => $value) { if (isset($vars[$option])) { $this->{$option} = $value; } else { throw new Exception('Ошибочка 2'); } } } } abstract protected function getDefaultOptions(): array; } class Length extends Constraint { public $min = 1; public $max; public $minMessage; public $maxMessage; public function __construct(array $options = null) { parent::__construct($options); } protected function getDefaultOptions(): array { return [ 'min' => 2, 'max' => 50, 'minMessage' => 'Значение меньше 2 символов', 'maxMessage' => 'Значение больше 50 символов' ]; } } interface ValidatorInterface { public function validate($value, Constraint $constraint): ?string; } class LengthValidator implements ValidatorInterface { public function validate($value, Constraint $constraint): ?string { if (!$constraint instanceof Length) { throw new Exception(); } $length = mb_strlen(trim($value)); if ($length < $constraint->min) { return $constraint->minMessage; } elseif ($length > $constraint->max) { return $constraint->maxMessage; } return null; } } $length = new Length([ 'min' => 3, 'max' => 50 ]); $lengthValidator = new LengthValidator(); $result = $lengthValidator->validate('Ян', $length); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gfBAC
function name:  (null)
number of ops:  17
compiled vars:  !0 = $length, !1 = $lengthValidator, !2 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   61     0  E >   DECLARE_CLASS                                                'lengthvalidator'
   81     1        NEW                                                  $3      'Length'
   82     2        SEND_VAL_EX                                                  <array>
   81     3        DO_FCALL                                          0          
          4        ASSIGN                                                       !0, $3
   85     5        NEW                                                  $6      'LengthValidator'
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !1, $6
   86     8        INIT_METHOD_CALL                                             !1, 'validate'
          9        SEND_VAL_EX                                                  '%D0%AF%D0%BD'
         10        SEND_VAR_EX                                                  !0
         11        DO_FCALL                                          0  $9      
         12        ASSIGN                                                       !2, $9
   88    13        INIT_FCALL                                                   'var_dump'
         14        SEND_VAR                                                     !2
         15        DO_ICALL                                                     
         16      > RETURN                                                       1

Class Constraint:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 19
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 41
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 40
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 40
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 35
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 41
Branch analysis from position: 19
filename:       /in/gfBAC
function name:  __construct
number of ops:  42
compiled vars:  !0 = $options, !1 = $defaultOptions, !2 = $value, !3 = $option, !4 = $vars
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV_INIT                                            !0      null
    7     1        INIT_METHOD_CALL                                             'getDefaultOptions'
          2        DO_FCALL                                          0  $5      
          3        ASSIGN                                                       !1, $5
    9     4        FETCH_THIS                                           ~7      
          5      > FE_RESET_R                                           $8      ~7, ->19
          6    > > FE_FETCH_R                                           ~9      $8, !2, ->19
          7    >   ASSIGN                                                       !3, ~9
   10     8        ISSET_ISEMPTY_DIM_OBJ                             0          !1, !3
          9      > JMPZ                                                         ~11, ->14
   11    10    >   FETCH_DIM_R                                          ~13     !1, !3
         11        ASSIGN_OBJ                                                   !3
         12        OP_DATA                                                      ~13
   10    13      > JMP                                                          ->18
   13    14    >   NEW                                                  $14     'Exception'
         15        SEND_VAL_EX                                                  '%D0%9E%D1%88%D0%B8%D0%B1%D0%BE%D1%87%D0%BA%D0%B0'
         16        DO_FCALL                                          0          
         17      > THROW                                             0          $14
    9    18    > > JMP                                                          ->6
         19    >   FE_FREE                                                      $8
   17    20        TYPE_CHECK                                      1020          !0
         21      > JMPZ                                                         ~16, ->41
   18    22    >   INIT_FCALL                                                   'get_object_vars'
         23        FETCH_THIS                                           ~17     
         24        SEND_VAL                                                     ~17
         25        DO_ICALL                                             $18     
         26        ASSIGN                                                       !4, $18
   20    27      > FE_RESET_R                                           $20     !0, ->40
         28    > > FE_FETCH_R                                           ~21     $20, !2, ->40
         29    >   ASSIGN                                                       !3, ~21
   21    30        ISSET_ISEMPTY_DIM_OBJ                             0          !4, !3
         31      > JMPZ                                                         ~23, ->35
   22    32    >   ASSIGN_OBJ                                                   !3
         33        OP_DATA                                                      !2
   21    34      > JMP                                                          ->39
   24    35    >   NEW                                                  $25     'Exception'
         36        SEND_VAL_EX                                                  '%D0%9E%D1%88%D0%B8%D0%B1%D0%BE%D1%87%D0%BA%D0%B0+2'
         37        DO_FCALL                                          0          
         38      > THROW                                             0          $25
   20    39    > > JMP                                                          ->28
         40    >   FE_FREE                                                      $20
   28    41    > > RETURN                                                       null

End of function __construct

Function getdefaultoptions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gfBAC
function name:  getDefaultOptions
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   VERIFY_RETURN_TYPE                                           
          1      > RETURN                                                       null

End of function getdefaultoptions

End of class Constraint.

Class Length:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gfBAC
function name:  __construct
number of ops:  5
compiled vars:  !0 = $options
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   40     0  E >   RECV_INIT                                            !0      null
   42     1        INIT_STATIC_METHOD_CALL                                      
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0          
   43     4      > RETURN                                                       null

End of function __construct

Function getdefaultoptions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gfBAC
function name:  getDefaultOptions
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   48     0  E > > RETURN                                                       <array>
   53     1*       VERIFY_RETURN_TYPE                                           
          2*     > RETURN                                                       null

End of function getdefaultoptions

End of class Length.

Class ValidatorInterface:
Function validate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gfBAC
function name:  validate
number of ops:  4
compiled vars:  !0 = $value, !1 = $constraint
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   58     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        VERIFY_RETURN_TYPE                                           
          3      > RETURN                                                       null

End of function validate

End of class ValidatorInterface.

Class LengthValidator:
Function validate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gfBAC
function name:  validate
number of ops:  29
compiled vars:  !0 = $value, !1 = $constraint, !2 = $length
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   63     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   65     2        INSTANCEOF                                           ~3      !1, 'Length'
          3        BOOL_NOT                                             ~4      ~3
          4      > JMPZ                                                         ~4, ->8
   66     5    >   NEW                                                  $5      'Exception'
          6        DO_FCALL                                          0          
          7      > THROW                                             0          $5
   69     8    >   INIT_FCALL                                                   'mb_strlen'
          9        FRAMELESS_ICALL_1                trim                ~7      !0
         10        SEND_VAL                                                     ~7
         11        DO_ICALL                                             $8      
         12        ASSIGN                                                       !2, $8
   71    13        FETCH_OBJ_R                                          ~10     !1, 'min'
         14        IS_SMALLER                                                   !2, ~10
         15      > JMPZ                                                         ~11, ->20
   72    16    >   FETCH_OBJ_R                                          ~12     !1, 'minMessage'
         17        VERIFY_RETURN_TYPE                                           ~12
         18      > RETURN                                                       ~12
   71    19*       JMP                                                          ->26
   73    20    >   FETCH_OBJ_R                                          ~13     !1, 'max'
         21        IS_SMALLER                                                   ~13, !2
         22      > JMPZ                                                         ~14, ->26
   74    23    >   FETCH_OBJ_R                                          ~15     !1, 'maxMessage'
         24        VERIFY_RETURN_TYPE                                           ~15
         25      > RETURN                                                       ~15
   77    26    > > RETURN                                                       null
   78    27*       VERIFY_RETURN_TYPE                                           
         28*     > RETURN                                                       null

End of function validate

End of class LengthValidator.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
177 ms | 2044 KiB | 18 Q