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('Score should be between 0 and 100'); } } public function analyzeScore(): Array { return $results = [ 'Status' => $this->determineStatus(), 'Grade' => $this->calculateGrade(), 'Number' => $this->number, 'Type' => $this->findType(), ]; } 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(77, 4); $results =$scoreAnalyzer->analyzeScore(); printf("Status: %s \n Grade: %s", $results['Status'], $results['Grade']); } catch (Throwable $e) { echo $e->getMessage(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 16
Branch analysis from position: 16
2 jumps found. (Code = 107) Position 1 = 17, Position 2 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B05gj
function name:  (null)
number of ops:  21
compiled vars:  !0 = $scoreAnalyzer, !1 = $results, !2 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   50     0  E >   NEW                                                  $3      'ScoreAnalyzer'
          1        SEND_VAL_EX                                                  77
          2        SEND_VAL_EX                                                  4
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !0, $3
   51     5        INIT_METHOD_CALL                                             !0, 'analyzeScore'
          6        DO_FCALL                                          0  $6      
          7        ASSIGN                                                       !1, $6
   52     8        INIT_FCALL                                                   'printf'
          9        SEND_VAL                                                     'Status%3A+%25s+%0A+Grade%3A+%25s'
         10        FETCH_DIM_R                                          ~8      !1, 'Status'
         11        SEND_VAL                                                     ~8
         12        FETCH_DIM_R                                          ~9      !1, 'Grade'
         13        SEND_VAL                                                     ~9
         14        DO_ICALL                                                     
         15      > JMP                                                          ->20
   53    16  E > > CATCH                                           last         'Throwable'
   54    17    >   INIT_METHOD_CALL                                             !2, 'getMessage'
         18        DO_FCALL                                          0  $11     
         19        ECHO                                                         $11
   55    20    > > 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/B05gj
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                                                  'Score+should+be+between+0+and+100'
         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/B05gj
function name:  analyzeScore
number of ops:  16
compiled vars:  !0 = $results
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   INIT_METHOD_CALL                                             'determineStatus'
          1        DO_FCALL                                          0  $1      
          2        INIT_ARRAY                                           ~2      $1, 'Status'
   20     3        INIT_METHOD_CALL                                             'calculateGrade'
          4        DO_FCALL                                          0  $3      
          5        ADD_ARRAY_ELEMENT                                    ~2      $3, 'Grade'
   21     6        FETCH_OBJ_R                                          ~4      'number'
          7        ADD_ARRAY_ELEMENT                                    ~2      ~4, 'Number'
   22     8        INIT_METHOD_CALL                                             'findType'
          9        DO_FCALL                                          0  $5      
         10        ADD_ARRAY_ELEMENT                                    ~2      $5, 'Type'
   18    11        ASSIGN                                               ~6      !0, ~2
         12        VERIFY_RETURN_TYPE                                           ~6
         13      > RETURN                                                       ~6
   25    14*       VERIFY_RETURN_TYPE                                           
         15*     > 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/B05gj
function name:  determineStatus
number of ops:  10
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     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
   30     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/B05gj
function name:  calculateGrade
number of ops:  31
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   FETCH_OBJ_R                                          ~1      'score'
          1        IS_SMALLER                                           ~2      ~1, 60
          2        IS_IDENTICAL                                                 ~2, <true>
          3      > JMPNZ                                                        ~0, ->17
   36     4    >   FETCH_OBJ_R                                          ~3      'score'
          5        IS_SMALLER                                           ~4      ~3, 70
          6        IS_IDENTICAL                                                 ~4, <true>
          7      > JMPNZ                                                        ~0, ->19
   37     8    >   FETCH_OBJ_R                                          ~5      'score'
          9        IS_SMALLER                                           ~6      ~5, 80
         10        IS_IDENTICAL                                                 ~6, <true>
         11      > JMPNZ                                                        ~0, ->21
   38    12    >   FETCH_OBJ_R                                          ~7      'score'
         13        IS_SMALLER                                           ~8      ~7, 90
         14        IS_IDENTICAL                                                 ~8, <true>
         15      > JMPNZ                                                        ~0, ->23
         16    > > JMP                                                          ->25
   35    17    >   QM_ASSIGN                                            ~9      'F'
         18      > JMP                                                          ->27
   36    19    >   QM_ASSIGN                                            ~9      'D'
         20      > JMP                                                          ->27
   37    21    >   QM_ASSIGN                                            ~9      'C'
         22      > JMP                                                          ->27
   38    23    >   QM_ASSIGN                                            ~9      'B'
         24      > JMP                                                          ->27
   39    25    >   QM_ASSIGN                                            ~9      'A'
         26      > JMP                                                          ->27
         27    >   VERIFY_RETURN_TYPE                                           ~9
         28      > RETURN                                                       ~9
   41    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/B05gj
function name:  findType
number of ops:  11
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   45     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
   46     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:
162.81 ms | 1414 KiB | 14 Q