3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); class ScoreAnalyzer { /** * @throws InvalidArgumentException */ public function __construct(private readonly int $score, private readonly int $number){ if($score < 0 || $score > 100){ throw new InvalidArgumentException('Invalid score input'); } } public function analyzeScore(): void { echo "Score: $this->score \n"; $status = $this->determineStatus(); echo "Status: $status \n"; $grade = $this->calculateGrade(); echo "Grade: $grade\n"; echo "Number: $this->number\n"; $type = $this->findType(); echo "Type: $type\n"; } private function determineStatus(): string { return $this->score >= 60 ? "pass" : "fail"; } private function calculateGrade(): string { return match (true) { $this->score < 60 => 'F', $this->score < 70 => 'D', $this->score < 80 => 'C', $this->score < 90 => 'B', default => 'A', }; } private function findType(): string { return $this->number % 2 === 0 ? "even" : "odd"; } } try{ $scoreAnalyzer = new ScoreAnalyzer(-1, 4); $scoreAnalyzer->analyzeScore(); } catch (InvalidArgumentException $e){ echo $e->getMessage(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 8
Branch analysis from position: 8
2 jumps found. (Code = 107) Position 1 = 9, Position 2 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eFBuv
function name:  (null)
number of ops:  13
compiled vars:  !0 = $scoreAnalyzer, !1 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   55     0  E >   NEW                                                  $2      'ScoreAnalyzer'
          1        SEND_VAL_EX                                                  -1
          2        SEND_VAL_EX                                                  4
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !0, $2
   56     5        INIT_METHOD_CALL                                             !0, 'analyzeScore'
          6        DO_FCALL                                          0          
          7      > JMP                                                          ->12
   57     8  E > > CATCH                                           last         'InvalidArgumentException'
   58     9    >   INIT_METHOD_CALL                                             !1, 'getMessage'
         10        DO_FCALL                                          0  $6      
         11        ECHO                                                         $6
   59    12    > > RETURN                                                       1

Class ScoreAnalyzer:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/eFBuv
function name:  __construct
number of ops:  16
compiled vars:  !0 = $score, !1 = $number
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        ASSIGN_OBJ                                                   'score'
          3        OP_DATA                                                      !0
          4        ASSIGN_OBJ                                                   'number'
          5        OP_DATA                                                      !1
   10     6        IS_SMALLER                                           ~2      !0, 0
          7      > JMPNZ_EX                                             ~2      ~2, ->10
          8    >   IS_SMALLER                                           ~3      100, !0
          9        BOOL                                                 ~2      ~3
         10    > > JMPZ                                                         ~2, ->15
   11    11    >   NEW                                                  $4      'InvalidArgumentException'
         12        SEND_VAL_EX                                                  'Invalid+score+input'
         13        DO_FCALL                                          0          
         14      > THROW                                             0          $4
   13    15    > > RETURN                                                       null

End of function __construct

Function analyzescore:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eFBuv
function name:  analyzeScore
number of ops:  32
compiled vars:  !0 = $status, !1 = $grade, !2 = $type
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   ROPE_INIT                                         3  ~5      'Score%3A+'
          1        FETCH_OBJ_R                                          ~3      'score'
          2        ROPE_ADD                                          1  ~5      ~5, ~3
          3        ROPE_END                                          2  ~4      ~5, '+%0A'
          4        ECHO                                                         ~4
   20     5        INIT_METHOD_CALL                                             'determineStatus'
          6        DO_FCALL                                          0  $7      
          7        ASSIGN                                                       !0, $7
   21     8        ROPE_INIT                                         3  ~10     'Status%3A+'
          9        ROPE_ADD                                          1  ~10     ~10, !0
         10        ROPE_END                                          2  ~9      ~10, '+%0A'
         11        ECHO                                                         ~9
   23    12        INIT_METHOD_CALL                                             'calculateGrade'
         13        DO_FCALL                                          0  $12     
         14        ASSIGN                                                       !1, $12
   24    15        ROPE_INIT                                         3  ~15     'Grade%3A+'
         16        ROPE_ADD                                          1  ~15     ~15, !1
         17        ROPE_END                                          2  ~14     ~15, '%0A'
         18        ECHO                                                         ~14
   26    19        ROPE_INIT                                         3  ~19     'Number%3A+'
         20        FETCH_OBJ_R                                          ~17     'number'
         21        ROPE_ADD                                          1  ~19     ~19, ~17
         22        ROPE_END                                          2  ~18     ~19, '%0A'
         23        ECHO                                                         ~18
   28    24        INIT_METHOD_CALL                                             'findType'
         25        DO_FCALL                                          0  $21     
         26        ASSIGN                                                       !2, $21
   29    27        ROPE_INIT                                         3  ~24     'Type%3A+'
         28        ROPE_ADD                                          1  ~24     ~24, !2
         29        ROPE_END                                          2  ~23     ~24, '%0A'
         30        ECHO                                                         ~23
   30    31      > RETURN                                                       null

End of function analyzescore

Function determinestatus:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eFBuv
function name:  determineStatus
number of ops:  10
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   FETCH_OBJ_R                                          ~0      'score'
          1        IS_SMALLER_OR_EQUAL                                          60, ~0
          2      > JMPZ                                                         ~1, ->5
          3    >   QM_ASSIGN                                            ~2      'pass'
          4      > JMP                                                          ->6
          5    >   QM_ASSIGN                                            ~2      'fail'
          6    >   VERIFY_RETURN_TYPE                                           ~2
          7      > RETURN                                                       ~2
   35     8*       VERIFY_RETURN_TYPE                                           
          9*     > RETURN                                                       null

End of function determinestatus

Function calculategrade:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 21
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 23
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
filename:       /in/eFBuv
function name:  calculateGrade
number of ops:  31
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   40     0  E >   FETCH_OBJ_R                                          ~1      'score'
          1        IS_SMALLER                                           ~2      ~1, 60
          2        IS_IDENTICAL                                                 ~2, <true>
          3      > JMPNZ                                                        ~0, ->17
   41     4    >   FETCH_OBJ_R                                          ~3      'score'
          5        IS_SMALLER                                           ~4      ~3, 70
          6        IS_IDENTICAL                                                 ~4, <true>
          7      > JMPNZ                                                        ~0, ->19
   42     8    >   FETCH_OBJ_R                                          ~5      'score'
          9        IS_SMALLER                                           ~6      ~5, 80
         10        IS_IDENTICAL                                                 ~6, <true>
         11      > JMPNZ                                                        ~0, ->21
   43    12    >   FETCH_OBJ_R                                          ~7      'score'
         13        IS_SMALLER                                           ~8      ~7, 90
         14        IS_IDENTICAL                                                 ~8, <true>
         15      > JMPNZ                                                        ~0, ->23
         16    > > JMP                                                          ->25
   40    17    >   QM_ASSIGN                                            ~9      'F'
         18      > JMP                                                          ->27
   41    19    >   QM_ASSIGN                                            ~9      'D'
         20      > JMP                                                          ->27
   42    21    >   QM_ASSIGN                                            ~9      'C'
         22      > JMP                                                          ->27
   43    23    >   QM_ASSIGN                                            ~9      'B'
         24      > JMP                                                          ->27
   44    25    >   QM_ASSIGN                                            ~9      'A'
         26      > JMP                                                          ->27
         27    >   VERIFY_RETURN_TYPE                                           ~9
         28      > RETURN                                                       ~9
   46    29*       VERIFY_RETURN_TYPE                                           
         30*     > RETURN                                                       null

End of function calculategrade

Function findtype:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eFBuv
function name:  findType
number of ops:  11
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   50     0  E >   FETCH_OBJ_R                                          ~0      'number'
          1        MOD                                                  ~1      ~0, 2
          2        IS_IDENTICAL                                                 ~1, 0
          3      > JMPZ                                                         ~2, ->6
          4    >   QM_ASSIGN                                            ~3      'even'
          5      > JMP                                                          ->7
          6    >   QM_ASSIGN                                            ~3      'odd'
          7    >   VERIFY_RETURN_TYPE                                           ~3
          8      > RETURN                                                       ~3
   51     9*       VERIFY_RETURN_TYPE                                           
         10*     > RETURN                                                       null

End of function findtype

End of class ScoreAnalyzer.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.1 ms | 1411 KiB | 13 Q