3v4l.org

run code in 300+ PHP versions simultaneously
<?php # The blueprint for designing creatures for your game interface LivingBeing { public function dealDamage(LivingBeing $opponent); public function takeDamage(int $damage); } interface Race { public function raceName(): string; } class Human implements LivingBeing, Race { private $hp = 150; private $offensiveStrength = 30; public function dealDamage(LivingBeing $opponent) { $opponent->takeDamage($this->offensiveStrength); } public function takeDamage(int $opponent) { } public function raceName(): string { return 'Human'; } } class Elf implements LivingBeing, Race { private $hp = 100; private $offensiveStrength = 30; public function dealDamage(LivingBeing $opponent) { $opponent->takeDamage($this->offensiveStrength); } public function takeDamage(int $opponent) { } public function raceName(): string { return 'Elf'; } } class Dwarf implements LivingBeing, Race { private $hp = 300; private $offensiveStrength = 30; public function dealDamage(LivingBeing $opponent) { $opponent->takeDamage($this->offensiveStrength); } public function takeDamage(int $opponent) { } public function raceName(): string { return 'Dwarf'; } } # I am a junior dev, I am just going to write this code class Centaur implements LivingBeing, Race { private $hp = 300; private $offensiveStrength = 30; public function dealDamage(LivingBeing $opponent) { $opponent->takeDamage($this->offensiveStrength); } public function takeDamage(int $opponent) { } public function raceName(): string { return 'Centaur'; } } class Orc implements LivingBeing, Race { private $hp = 300; private $offensiveStrength = 30; public function dealDamage(LivingBeing $opponent) { $opponent->takeDamage($this->offensiveStrength); } public function takeDamage(int $opponent) { } public function raceName(): string { return 'Orc'; } } function listTheirRace (Race ...$list) { $string = ''; foreach ($list as $being) { $string .= $being->raceName() . "\n"; } return $string; } $Adam = new Human; $Lucas = new Elf; $Jack = new Dwarf; # Let's fight! $Gabrielle = new Centaur; $Guthakug = new Orc; echo listTheirRace(...[$Adam, $Lucas, $Jack, $Gabrielle, $Guthakug]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  (null)
number of ops:  31
compiled vars:  !0 = $Adam, !1 = $Lucas, !2 = $Jack, !3 = $Gabrielle, !4 = $Guthakug
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   DECLARE_CLASS                                            'human'
   29     1        DECLARE_CLASS                                            'elf'
   45     2        DECLARE_CLASS                                            'dwarf'
   64     3        DECLARE_CLASS                                            'centaur'
   80     4        DECLARE_CLASS                                            'orc'
  106     5        NEW                                              $5      'Human'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $5
  108     8        NEW                                              $8      'Elf'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $8
  110    11        NEW                                              $11     'Dwarf'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !2, $11
  114    14        NEW                                              $14     'Centaur'
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !3, $14
  115    17        NEW                                              $17     'Orc'
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !4, $17
  118    20        INIT_FCALL                                               'listtheirrace'
         21        INIT_ARRAY                                       ~20     !0
         22        ADD_ARRAY_ELEMENT                                ~20     !1
         23        ADD_ARRAY_ELEMENT                                ~20     !2
         24        ADD_ARRAY_ELEMENT                                ~20     !3
         25        ADD_ARRAY_ELEMENT                                ~20     !4
         26        SEND_UNPACK                                              ~20
         27        CHECK_UNDEF_ARGS                                         
         28        DO_FCALL                                      1  $21     
         29        ECHO                                                     $21
         30      > RETURN                                                   1

Function listtheirrace:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/Tt9tF
function name:  listTheirRace
number of ops:  12
compiled vars:  !0 = $list, !1 = $string, !2 = $being
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   RECV_VARIADIC                                    !0      
   98     1        ASSIGN                                                   !1, ''
   99     2      > FE_RESET_R                                       $4      !0, ->9
          3    > > FE_FETCH_R                                               $4, !2, ->9
  100     4    >   INIT_METHOD_CALL                                         !2, 'raceName'
          5        DO_FCALL                                      0  $5      
          6        CONCAT                                           ~6      $5, '%0A'
          7        ASSIGN_OP                                     8          !1, ~6
   99     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $4
  103    10      > RETURN                                                   !1
  104    11*     > RETURN                                                   null

End of function listtheirrace

Class LivingBeing:
Function dealdamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  dealDamage
number of ops:  2
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function dealdamage

Function takedamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  takeDamage
number of ops:  2
compiled vars:  !0 = $damage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function takedamage

End of class LivingBeing.

Class Race:
Function racename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  raceName
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function racename

End of class Race.

Class Human:
Function dealdamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  dealDamage
number of ops:  7
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        INIT_METHOD_CALL                                         !0, 'takeDamage'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'offensiveStrength'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0          
   19     6      > RETURN                                                   null

End of function dealdamage

Function takedamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  takeDamage
number of ops:  2
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1      > RETURN                                                   null

End of function takedamage

Function racename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  raceName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E > > RETURN                                                   'Human'
   26     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function racename

End of class Human.

Class Elf:
Function dealdamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  dealDamage
number of ops:  7
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        INIT_METHOD_CALL                                         !0, 'takeDamage'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'offensiveStrength'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0          
   35     6      > RETURN                                                   null

End of function dealdamage

Function takedamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  takeDamage
number of ops:  2
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   38     1      > RETURN                                                   null

End of function takedamage

Function racename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  raceName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E > > RETURN                                                   'Elf'
   42     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function racename

End of class Elf.

Class Dwarf:
Function dealdamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  dealDamage
number of ops:  7
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   50     1        INIT_METHOD_CALL                                         !0, 'takeDamage'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'offensiveStrength'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0          
   51     6      > RETURN                                                   null

End of function dealdamage

Function takedamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  takeDamage
number of ops:  2
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1      > RETURN                                                   null

End of function takedamage

Function racename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  raceName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E > > RETURN                                                   'Dwarf'
   58     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function racename

End of class Dwarf.

Class Centaur:
Function dealdamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  dealDamage
number of ops:  7
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
   69     1        INIT_METHOD_CALL                                         !0, 'takeDamage'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'offensiveStrength'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0          
   70     6      > RETURN                                                   null

End of function dealdamage

Function takedamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  takeDamage
number of ops:  2
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
   73     1      > RETURN                                                   null

End of function takedamage

Function racename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  raceName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E > > RETURN                                                   'Centaur'
   77     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function racename

End of class Centaur.

Class Orc:
Function dealdamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  dealDamage
number of ops:  7
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
   85     1        INIT_METHOD_CALL                                         !0, 'takeDamage'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'offensiveStrength'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0          
   86     6      > RETURN                                                   null

End of function dealdamage

Function takedamage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  takeDamage
number of ops:  2
compiled vars:  !0 = $opponent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   RECV                                             !0      
   89     1      > RETURN                                                   null

End of function takedamage

Function racename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Tt9tF
function name:  raceName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E > > RETURN                                                   'Orc'
   93     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function racename

End of class Orc.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.34 ms | 1415 KiB | 14 Q