3v4l.org

run code in 300+ PHP versions simultaneously
<?php enum Colour { case Red; case Blue; case Green; public static function fromCaseName (string $name): ?self { $cases = self::cases(); foreach ($cases as $selCase) { if ($selCase->name === $name) { return $selCase; } } return null; } public function toRgb () { return match ($this) { self::Red => "255, 0, 0", self::Blue => "0, 255, 0", self::Green => "0, 0, 255" }; } public function toHex () { return match ($this) { self::Red => "#ff0000", self::Blue => "#00ff00", self::Green => "#0000ff" }; } public function toCmyk () { return match ($this) { self::Red => "0% 100% 100% 0%", self::Blue => "100% 0% 100% 0%", self::Green => "100% 100% 0% 0%" }; } } var_dump(Colour::Red); var_dump(Colour::Red->toRgb()); var_dump(Colour::Red->toHex()); var_dump(Colour::Red->toCmyk()); var_dump(Colour::fromCaseName('Red')); var_dump(Colour::fromCaseName('Red')->toRgb());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rskpC
function name:  (null)
number of ops:  38
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'colour'
   44     1        INIT_FCALL                                               'var_dump'
          2        FETCH_CLASS_CONSTANT                             ~0      'Colour', 'Red'
          3        SEND_VAL                                                 ~0
          4        DO_ICALL                                                 
   45     5        INIT_FCALL                                               'var_dump'
          6        FETCH_CLASS_CONSTANT                             ~2      'Colour', 'Red'
          7        INIT_METHOD_CALL                                         ~2, 'toRgb'
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                                 
   46    11        INIT_FCALL                                               'var_dump'
         12        FETCH_CLASS_CONSTANT                             ~5      'Colour', 'Red'
         13        INIT_METHOD_CALL                                         ~5, 'toHex'
         14        DO_FCALL                                      0  $6      
         15        SEND_VAR                                                 $6
         16        DO_ICALL                                                 
   47    17        INIT_FCALL                                               'var_dump'
         18        FETCH_CLASS_CONSTANT                             ~8      'Colour', 'Red'
         19        INIT_METHOD_CALL                                         ~8, 'toCmyk'
         20        DO_FCALL                                      0  $9      
         21        SEND_VAR                                                 $9
         22        DO_ICALL                                                 
   48    23        INIT_FCALL                                               'var_dump'
         24        INIT_STATIC_METHOD_CALL                                  'Colour', 'fromCaseName'
         25        SEND_VAL_EX                                              'Red'
         26        DO_FCALL                                      0  $11     
         27        SEND_VAR                                                 $11
         28        DO_ICALL                                                 
   49    29        INIT_FCALL                                               'var_dump'
         30        INIT_STATIC_METHOD_CALL                                  'Colour', 'fromCaseName'
         31        SEND_VAL_EX                                              'Red'
         32        DO_FCALL                                      0  $13     
         33        INIT_METHOD_CALL                                         $13, 'toRgb'
         34        DO_FCALL                                      0  $14     
         35        SEND_VAR                                                 $14
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Class Colour:
Function fromcasename:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/rskpC
function name:  fromCaseName
number of ops:  17
compiled vars:  !0 = $name, !1 = $cases, !2 = $selCase
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        INIT_STATIC_METHOD_CALL                                  'cases'
          2        DO_FCALL                                      0  $3      
          3        ASSIGN                                                   !1, $3
   10     4      > FE_RESET_R                                       $5      !1, ->13
          5    > > FE_FETCH_R                                               $5, !2, ->13
   11     6    >   FETCH_OBJ_R                                      ~6      !2, 'name'
          7        IS_IDENTICAL                                             !0, ~6
          8      > JMPZ                                                     ~7, ->12
   12     9    >   VERIFY_RETURN_TYPE                                       !2
         10        FE_FREE                                                  $5
         11      > RETURN                                                   !2
   10    12    > > JMP                                                      ->5
         13    >   FE_FREE                                                  $5
   16    14      > RETURN                                                   null
   17    15*       VERIFY_RETURN_TYPE                                       
         16*     > RETURN                                                   null

End of function fromcasename

Function torgb:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 197) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
filename:       /in/rskpC
function name:  toRgb
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_THIS                                       ~0      
   21     1        FETCH_CLASS_CONSTANT                             ~2      'Red'
          2        CASE_STRICT                                              ~0, ~2
          3      > JMPNZ                                                    ~1, ->12
   22     4    >   FETCH_CLASS_CONSTANT                             ~3      'Blue'
          5        CASE_STRICT                                              ~0, ~3
          6      > JMPNZ                                                    ~1, ->14
   23     7    >   FETCH_CLASS_CONSTANT                             ~4      'Green'
          8        CASE_STRICT                                              ~0, ~4
          9      > JMPNZ                                                    ~1, ->16
         10    > > JMP                                                      ->11
         11    > > MATCH_ERROR                                              ~0
   21    12    >   QM_ASSIGN                                        ~5      '255%2C+0%2C+0'
         13      > JMP                                                      ->18
   22    14    >   QM_ASSIGN                                        ~5      '0%2C+255%2C+0'
         15      > JMP                                                      ->18
   23    16    >   QM_ASSIGN                                        ~5      '0%2C+0%2C+255'
         17      > JMP                                                      ->18
         18    >   FREE                                                     ~0
         19      > RETURN                                                   ~5
   25    20*     > RETURN                                                   null

End of function torgb

Function tohex:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 197) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
filename:       /in/rskpC
function name:  toHex
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_THIS                                       ~0      
   29     1        FETCH_CLASS_CONSTANT                             ~2      'Red'
          2        CASE_STRICT                                              ~0, ~2
          3      > JMPNZ                                                    ~1, ->12
   30     4    >   FETCH_CLASS_CONSTANT                             ~3      'Blue'
          5        CASE_STRICT                                              ~0, ~3
          6      > JMPNZ                                                    ~1, ->14
   31     7    >   FETCH_CLASS_CONSTANT                             ~4      'Green'
          8        CASE_STRICT                                              ~0, ~4
          9      > JMPNZ                                                    ~1, ->16
         10    > > JMP                                                      ->11
         11    > > MATCH_ERROR                                              ~0
   29    12    >   QM_ASSIGN                                        ~5      '%23ff0000'
         13      > JMP                                                      ->18
   30    14    >   QM_ASSIGN                                        ~5      '%2300ff00'
         15      > JMP                                                      ->18
   31    16    >   QM_ASSIGN                                        ~5      '%230000ff'
         17      > JMP                                                      ->18
         18    >   FREE                                                     ~0
         19      > RETURN                                                   ~5
   33    20*     > RETURN                                                   null

End of function tohex

Function tocmyk:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 197) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
filename:       /in/rskpC
function name:  toCmyk
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   FETCH_THIS                                       ~0      
   37     1        FETCH_CLASS_CONSTANT                             ~2      'Red'
          2        CASE_STRICT                                              ~0, ~2
          3      > JMPNZ                                                    ~1, ->12
   38     4    >   FETCH_CLASS_CONSTANT                             ~3      'Blue'
          5        CASE_STRICT                                              ~0, ~3
          6      > JMPNZ                                                    ~1, ->14
   39     7    >   FETCH_CLASS_CONSTANT                             ~4      'Green'
          8        CASE_STRICT                                              ~0, ~4
          9      > JMPNZ                                                    ~1, ->16
         10    > > JMP                                                      ->11
         11    > > MATCH_ERROR                                              ~0
   37    12    >   QM_ASSIGN                                        ~5      '0%25+100%25+100%25+0%25'
         13      > JMP                                                      ->18
   38    14    >   QM_ASSIGN                                        ~5      '100%25+0%25+100%25+0%25'
         15      > JMP                                                      ->18
   39    16    >   QM_ASSIGN                                        ~5      '100%25+100%25+0%25+0%25'
         17      > JMP                                                      ->18
         18    >   FREE                                                     ~0
         19      > RETURN                                                   ~5
   41    20*     > RETURN                                                   null

End of function tocmyk

End of class Colour.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.05 ms | 1010 KiB | 14 Q