3v4l.org

run code in 500+ PHP versions simultaneously
<?php abstract class StringObject { protected string $string; public function __tostring(): string { return $this->string; } } class StringObjectException extends Exception {} 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 Exception {}; class NotEmptyString extends StringObject { public function __construct(string $string) { if ('' === $string) { throw new EmptyStringException('Expected not empty string.'); } $this->string = $string; } } class TooLongStringException extends Exception {}; class TenLettersString extends StringObject { private const MAX_LETTERS_COUNT = 10; public function __construct(CountableString $string) { if (self::MAX_LETTERS_COUNT < $string->countLetters()) { throw new TooLongStringException( sprintf('Expected string not longer then: "%d letters" got: "%s"', self::MAX_LETTERS_COUNT, $string ) ); } $this->string = $string; } } $countableString = new CountableString('Тестовая строка'); $notEmptyString = new NotEmptyString($countableString); echo $countableString->countLetters() . PHP_EOL; echo $countableString . PHP_EOL; $tenLetterLongString = new TenLettersString($countableString);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XhAE2
function name:  (null)
number of ops:  23
compiled vars:  !0 = $countableString, !1 = $notEmptyString, !2 = $tenLetterLongString
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'stringobject'
   13     1        DECLARE_CLASS                                                'countablestring', 'stringobject'
   28     2        DECLARE_CLASS                                                'notemptystring', 'stringobject'
   40     3        DECLARE_CLASS                                                'tenlettersstring', 'stringobject'
   57     4        NEW                                                  $3      'CountableString'
          5        SEND_VAL_EX                                                  '%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'
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !0, $3
   58     8        NEW                                                  $6      'NotEmptyString'
          9        SEND_VAR_EX                                                  !0
         10        DO_FCALL                                          0          
         11        ASSIGN                                                       !1, $6
   60    12        INIT_METHOD_CALL                                             !0, 'countLetters'
         13        DO_FCALL                                          0  $9      
         14        CONCAT                                               ~10     $9, '%0A'
         15        ECHO                                                         ~10
   61    16        CONCAT                                               ~11     !0, '%0A'
         17        ECHO                                                         ~11
   63    18        NEW                                                  $12     'TenLettersString'
         19        SEND_VAR_EX                                                  !0
         20        DO_FCALL                                          0          
         21        ASSIGN                                                       !2, $12
         22      > RETURN                                                       1

Class StringObject:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XhAE2
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: [no user functions]
Class CountableString:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XhAE2
function name:  __construct
number of ops:  9
compiled vars:  !0 = $string
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV                                                 !0      
   17     1        ASSIGN_OBJ                                                   'string'
          2        OP_DATA                                                      !0
   18     3        INIT_FCALL                                                   'mb_strlen'
          4        SEND_VAR                                                     !0
          5        DO_ICALL                                             $3      
          6        ASSIGN_OBJ                                                   'lettersCount'
          7        OP_DATA                                                      $3
   19     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/XhAE2
function name:  countLetters
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   FETCH_OBJ_R                                          ~0      'lettersCount'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
   23     3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function countletters

End of class CountableString.

Class EmptyStringException: [no user functions]
Class NotEmptyString:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XhAE2
function name:  __construct
number of ops:  10
compiled vars:  !0 = $string
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   RECV                                                 !0      
   30     1        IS_IDENTICAL                                                 !0, ''
          2      > JMPZ                                                         ~1, ->7
   31     3    >   NEW                                                  $2      'EmptyStringException'
          4        SEND_VAL_EX                                                  'Expected+not+empty+string.'
          5        DO_FCALL                                          0          
          6      > THROW                                             0          $2
   34     7    >   ASSIGN_OBJ                                                   'string'
          8        OP_DATA                                                      !0
   35     9      > RETURN                                                       null

End of function __construct

End of class NotEmptyString.

Class TooLongStringException: [no user functions]
Class TenLettersString:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XhAE2
function name:  __construct
number of ops:  18
compiled vars:  !0 = $string
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   RECV                                                 !0      
   44     1        INIT_METHOD_CALL                                             !0, 'countLetters'
          2        DO_FCALL                                          0  $1      
          3        IS_SMALLER                                                   10, $1
          4      > JMPZ                                                         ~2, ->15
   45     5    >   NEW                                                  $3      'TooLongStringException'
   48     6        ROPE_INIT                                         5  ~6      'Expected+string+not+longer+then%3A+%22'
          7        CAST                                              4  ~4      10
          8        ROPE_ADD                                          1  ~6      ~6, ~4
          9        ROPE_ADD                                          2  ~6      ~6, '+letters%22+got%3A+%22'
         10        ROPE_ADD                                          3  ~6      ~6, !0
         11        ROPE_END                                          4  ~5      ~6, '%22'
         12        SEND_VAL_EX                                                  ~5
   45    13        DO_FCALL                                          0          
   48    14      > THROW                                             0          $3
   53    15    >   ASSIGN_OBJ                                                   'string'
         16        OP_DATA                                                      !0
   54    17      > RETURN                                                       null

End of function __construct

End of class TenLettersString.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.2 ms | 1774 KiB | 14 Q