3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class StringObject { protected string $string; public function __toString(): string { return $this->string; } } class StringObjectException extends Exception { public readonly string $string; public function __construct(string $string, string $message = "", int $code = 0, Throwable $previous = null) { parent::__construct($message, $code, $previous); $this->string = $string; } } class CountableString extends StringObject { private int $lettersCount; public function __construct(string $string) { $this->string = $string; $this->lettersCount = mb_strlen($string); } public function countLetters(): int { return $this->lettersCount; } } class EmptyStringException extends StringObjectException {} class NotEmptyString extends StringObject { /** * @throws EmptyStringException */ public function __construct(string $string) { if ('' === $string) { throw new EmptyStringException(string: $string, message: 'Expected not empty string.'); } $this->string = $string; } } class TooLongStringException extends StringObjectException {} class LimitedLengthString extends StringObject { /** * @throws TooLongStringException */ public function __construct(CountableString $string, int $maxLength) { if ($maxLength < $string->countLetters()) { throw new TooLongStringException(string: $string, message: 'Too long string'); } $this->string = $string; } } class TenLettersStringValidator { private const MAX_LETTERS_COUNT = 10; private const ERROR_MESSAGE = 'Expected string not longer then: "%d letters" got: "%s"'; public function __invoke(string $string): ?string { $error = null; try { new LimitedLengthString(new CountableString($string), self::MAX_LETTERS_COUNT); } catch (TooLongStringException $exception) { $error = sprintf(self::ERROR_MESSAGE, self::MAX_LETTERS_COUNT, $exception->string ); } return $error; } } $validators = [new TenLettersStringValidator]; $errors = []; $string = 'Тестовая строка'; foreach ($validators as $validator) { $result = $validator($string); $result ? $errors[] = $result : null; } var_dump($errors);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 24
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/jGPb4
function name:  (null)
number of ops:  29
compiled vars:  !0 = $validators, !1 = $errors, !2 = $string, !3 = $validator, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'stringobject'
   21     1        DECLARE_CLASS                                            'countablestring', 'stringobject'
   36     2        DECLARE_CLASS                                            'notemptystring', 'stringobject'
   51     3        DECLARE_CLASS                                            'limitedlengthstring', 'stringobject'
   85     4        NEW                                              $5      'TenLettersStringValidator'
          5        DO_FCALL                                      0          
          6        INIT_ARRAY                                       ~7      $5
          7        ASSIGN                                                   !0, ~7
   86     8        ASSIGN                                                   !1, <array>
   87     9        ASSIGN                                                   !2, '%D0%A2%D0%B5%D1%81%D1%82%D0%BE%D0%B2%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%BE%D0%BA%D0%B0'
   89    10      > FE_RESET_R                                       $11     !0, ->24
         11    > > FE_FETCH_R                                               $11, !3, ->24
   90    12    >   INIT_DYNAMIC_CALL                                        !3
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $12     
         15        ASSIGN                                                   !4, $12
   91    16      > JMPZ                                                     !4, ->21
         17    >   ASSIGN_DIM                                       ~14     !1
         18        OP_DATA                                                  !4
         19        QM_ASSIGN                                        ~15     ~14
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~15     null
         22    >   FREE                                                     ~15
   89    23      > JMP                                                      ->11
         24    >   FE_FREE                                                  $11
   94    25        INIT_FCALL                                               'var_dump'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Class StringObject:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  __toString
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   FETCH_OBJ_R                                      ~0      'string'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
    8     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function __tostring

End of class StringObject.

Class StringObjectException:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  __construct
number of ops:  12
compiled vars:  !0 = $string, !1 = $message, !2 = $code, !3 = $previous
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
          2        RECV_INIT                                        !2      0
          3        RECV_INIT                                        !3      null
   16     4        INIT_STATIC_METHOD_CALL                                  
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        SEND_VAR_EX                                              !3
          8        DO_FCALL                                      0          
   17     9        ASSIGN_OBJ                                               'string'
         10        OP_DATA                                                  !0
   18    11      > RETURN                                                   null

End of function __construct

End of class StringObjectException.

Class CountableString:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  __construct
number of ops:  9
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        ASSIGN_OBJ                                               'string'
          2        OP_DATA                                                  !0
   26     3        INIT_FCALL                                               'mb_strlen'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        ASSIGN_OBJ                                               'lettersCount'
          7        OP_DATA                                                  $3
   27     8      > RETURN                                                   null

End of function __construct

Function countletters:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  countLetters
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_OBJ_R                                      ~0      'lettersCount'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   31     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function countletters

End of class CountableString.

Class EmptyStringException:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  __construct
number of ops:  12
compiled vars:  !0 = $string, !1 = $message, !2 = $code, !3 = $previous
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
          2        RECV_INIT                                        !2      0
          3        RECV_INIT                                        !3      null
   16     4        INIT_STATIC_METHOD_CALL                                  
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        SEND_VAR_EX                                              !3
          8        DO_FCALL                                      0          
   17     9        ASSIGN_OBJ                                               'string'
         10        OP_DATA                                                  !0
   18    11      > RETURN                                                   null

End of function __construct

End of class EmptyStringException.

Class NotEmptyString:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  __construct
number of ops:  12
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        IS_IDENTICAL                                             !0, ''
          2      > JMPZ                                                     ~1, ->9
   42     3    >   NEW                                              $2      'EmptyStringException'
          4        SEND_VAR_EX                                              !0, 'string'
          5        SEND_VAL_EX                                              'Expected+not+empty+string.', 'message'
          6        CHECK_UNDEF_ARGS                                         
          7        DO_FCALL                                      1          
          8      > THROW                                         0          $2
   45     9    >   ASSIGN_OBJ                                               'string'
         10        OP_DATA                                                  !0
   46    11      > RETURN                                                   null

End of function __construct

End of class NotEmptyString.

Class TooLongStringException:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  __construct
number of ops:  12
compiled vars:  !0 = $string, !1 = $message, !2 = $code, !3 = $previous
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
          2        RECV_INIT                                        !2      0
          3        RECV_INIT                                        !3      null
   16     4        INIT_STATIC_METHOD_CALL                                  
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        SEND_VAR_EX                                              !3
          8        DO_FCALL                                      0          
   17     9        ASSIGN_OBJ                                               'string'
         10        OP_DATA                                                  !0
   18    11      > RETURN                                                   null

End of function __construct

End of class TooLongStringException.

Class LimitedLengthString:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  __construct
number of ops:  15
compiled vars:  !0 = $string, !1 = $maxLength
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   56     2        INIT_METHOD_CALL                                         !0, 'countLetters'
          3        DO_FCALL                                      0  $2      
          4        IS_SMALLER                                               !1, $2
          5      > JMPZ                                                     ~3, ->12
   57     6    >   NEW                                              $4      'TooLongStringException'
          7        SEND_VAR_EX                                              !0, 'string'
          8        SEND_VAL_EX                                              'Too+long+string', 'message'
          9        CHECK_UNDEF_ARGS                                         
         10        DO_FCALL                                      1          
         11      > THROW                                         0          $4
   60    12    >   ASSIGN_OBJ                                               'string'
         13        OP_DATA                                                  !0
   61    14      > RETURN                                                   null

End of function __construct

End of class LimitedLengthString.

Class TenLettersStringValidator:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 11
Branch analysis from position: 11
2 jumps found. (Code = 107) Position 1 = 12, Position 2 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jGPb4
function name:  __invoke
number of ops:  23
compiled vars:  !0 = $string, !1 = $error, !2 = $exception
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
   69     1        ASSIGN                                                   !1, null
   72     2        NEW                                              $4      'LimitedLengthString'
          3        NEW                                              $5      'CountableString'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        SEND_VAR_NO_REF_EX                                       $5
          7        SEND_VAL_EX                                              10
          8        DO_FCALL                                      0          
          9        FREE                                                     $4
         10      > JMP                                                      ->19
   73    11  E > > CATCH                                       last         'TooLongStringException'
   74    12    >   INIT_FCALL                                               'sprintf'
         13        SEND_VAL                                                 'Expected+string+not+longer+then%3A+%22%25d+letters%22+got%3A+%22%25s%22'
   75    14        SEND_VAL                                                 10
   76    15        FETCH_OBJ_R                                      ~8      !2, 'string'
         16        SEND_VAL                                                 ~8
   74    17        DO_ICALL                                         $9      
         18        ASSIGN                                                   !1, $9
   80    19    >   VERIFY_RETURN_TYPE                                       !1
         20      > RETURN                                                   !1
   81    21*       VERIFY_RETURN_TYPE                                       
         22*     > RETURN                                                   null

End of function __invoke

End of class TenLettersStringValidator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.44 ms | 1017 KiB | 16 Q