3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); class Game { public function __construct( public readonly string $name ) {} } class GameCollection { private array $games = []; public function add(Game $game): void { $this->games[$game->name] = $game; } public function remove(Game $game): void { unset($this->games[$game->name]); } public function getAll(): array { return $this->games; } } class GameStore { public function __construct( private GameCollection $games, private GameCollection $loans ) {} public function addGame(Game $game): void { $this->games->add($game); } public function getAllGames(): array { return $this->games->getAll(); } public function checkOut(Game $game): void { $this->loans->add($game); $this->games->remove($game); } public function checkIn(Game $game): void { $this->loans->remove($game); $this->games->add($game); } public function getAllOnLoan(): array { return $this->loans->getAll(); } } $csgo = new Game('CS:GO'); $exp33 = new Game('Expedition 33'); $marioBros = new Game('Super Mario Bros'); $collection = new GameCollection(); $collection->add($csgo); $collection->add($exp33); $collection->add($marioBros); var_dump( 'Current collection:', $collection->getAll() ); $collection->remove($exp33); var_dump( 'Collection without Expedition 33:', $collection->getAll() ); $store = new GameStore( games: new GameCollection(), loans: new GameCollection() ); $store->addGame($csgo); $store->addGame($exp33); var_dump( 'GameStore', 'Available:', $store->getAllGames(), 'On loan:', $store->getAllOnLoan() ); $store->checkOut($csgo); var_dump( 'GameStore - checkOut', 'Available:', $store->getAllGames(), 'On loan:', $store->getAllOnLoan() ); $store->checkOut($exp33); $store->checkIn($csgo); var_dump( 'GameStore - checkIn & checkOut', 'Available:', $store->getAllGames(), 'On loan:', $store->getAllOnLoan() );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  (null)
number of ops:  98
compiled vars:  !0 = $csgo, !1 = $exp33, !2 = $marioBros, !3 = $collection, !4 = $store
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   57     0  E >   NEW                                                  $5      'Game'
          1        SEND_VAL_EX                                                  'CS%3AGO'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $5
   58     4        NEW                                                  $8      'Game'
          5        SEND_VAL_EX                                                  'Expedition+33'
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !1, $8
   59     8        NEW                                                  $11     'Game'
          9        SEND_VAL_EX                                                  'Super+Mario+Bros'
         10        DO_FCALL                                          0          
         11        ASSIGN                                                       !2, $11
   61    12        NEW                                                  $14     'GameCollection'
         13        DO_FCALL                                          0          
         14        ASSIGN                                                       !3, $14
   62    15        INIT_METHOD_CALL                                             !3, 'add'
         16        SEND_VAR_EX                                                  !0
         17        DO_FCALL                                          0          
   63    18        INIT_METHOD_CALL                                             !3, 'add'
         19        SEND_VAR_EX                                                  !1
         20        DO_FCALL                                          0          
   64    21        INIT_METHOD_CALL                                             !3, 'add'
         22        SEND_VAR_EX                                                  !2
         23        DO_FCALL                                          0          
   66    24        INIT_FCALL                                                   'var_dump'
   67    25        SEND_VAL                                                     'Current+collection%3A'
   68    26        INIT_METHOD_CALL                                             !3, 'getAll'
         27        DO_FCALL                                          0  $20     
         28        SEND_VAR                                                     $20
   66    29        DO_ICALL                                                     
   71    30        INIT_METHOD_CALL                                             !3, 'remove'
         31        SEND_VAR_EX                                                  !1
         32        DO_FCALL                                          0          
   72    33        INIT_FCALL                                                   'var_dump'
   73    34        SEND_VAL                                                     'Collection+without+Expedition+33%3A'
   74    35        INIT_METHOD_CALL                                             !3, 'getAll'
         36        DO_FCALL                                          0  $23     
         37        SEND_VAR                                                     $23
   72    38        DO_ICALL                                                     
   77    39        NEW                                                  $25     'GameStore'
   78    40        NEW                                                  $26     'GameCollection'
         41        DO_FCALL                                          0          
         42        SEND_VAR_NO_REF_EX                                           $26, 'games'
   79    43        NEW                                                  $28     'GameCollection'
         44        DO_FCALL                                          0          
         45        SEND_VAR_NO_REF_EX                                           $28, 'loans'
         46        CHECK_UNDEF_ARGS                                             
   77    47        DO_FCALL                                          1          
         48        ASSIGN                                                       !4, $25
   82    49        INIT_METHOD_CALL                                             !4, 'addGame'
         50        SEND_VAR_EX                                                  !0
         51        DO_FCALL                                          0          
   83    52        INIT_METHOD_CALL                                             !4, 'addGame'
         53        SEND_VAR_EX                                                  !1
         54        DO_FCALL                                          0          
   85    55        INIT_FCALL                                                   'var_dump'
   86    56        SEND_VAL                                                     'GameStore'
   87    57        SEND_VAL                                                     'Available%3A'
         58        INIT_METHOD_CALL                                             !4, 'getAllGames'
         59        DO_FCALL                                          0  $34     
         60        SEND_VAR                                                     $34
   88    61        SEND_VAL                                                     'On+loan%3A'
         62        INIT_METHOD_CALL                                             !4, 'getAllOnLoan'
         63        DO_FCALL                                          0  $35     
         64        SEND_VAR                                                     $35
   85    65        DO_ICALL                                                     
   91    66        INIT_METHOD_CALL                                             !4, 'checkOut'
         67        SEND_VAR_EX                                                  !0
         68        DO_FCALL                                          0          
   93    69        INIT_FCALL                                                   'var_dump'
   94    70        SEND_VAL                                                     'GameStore+-+checkOut'
   95    71        SEND_VAL                                                     'Available%3A'
         72        INIT_METHOD_CALL                                             !4, 'getAllGames'
         73        DO_FCALL                                          0  $38     
         74        SEND_VAR                                                     $38
   96    75        SEND_VAL                                                     'On+loan%3A'
         76        INIT_METHOD_CALL                                             !4, 'getAllOnLoan'
         77        DO_FCALL                                          0  $39     
         78        SEND_VAR                                                     $39
   93    79        DO_ICALL                                                     
   99    80        INIT_METHOD_CALL                                             !4, 'checkOut'
         81        SEND_VAR_EX                                                  !1
         82        DO_FCALL                                          0          
  100    83        INIT_METHOD_CALL                                             !4, 'checkIn'
         84        SEND_VAR_EX                                                  !0
         85        DO_FCALL                                          0          
  102    86        INIT_FCALL                                                   'var_dump'
  103    87        SEND_VAL                                                     'GameStore+-+checkIn+%26+checkOut'
  104    88        SEND_VAL                                                     'Available%3A'
         89        INIT_METHOD_CALL                                             !4, 'getAllGames'
         90        DO_FCALL                                          0  $43     
         91        SEND_VAR                                                     $43
  105    92        SEND_VAL                                                     'On+loan%3A'
         93        INIT_METHOD_CALL                                             !4, 'getAllOnLoan'
         94        DO_FCALL                                          0  $44     
         95        SEND_VAR                                                     $44
  102    96        DO_ICALL                                                     
  106    97      > RETURN                                                       1

Class Game:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        ASSIGN_OBJ                                                   'name'
          2        OP_DATA                                                      !0
    8     3      > RETURN                                                       null

End of function __construct

End of class Game.

Class GameCollection:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  add
number of ops:  6
compiled vars:  !0 = $game
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
   15     1        FETCH_OBJ_R                                          ~2      !0, 'name'
          2        FETCH_OBJ_W                                          $1      'games'
          3        ASSIGN_DIM                                                   $1, ~2
          4        OP_DATA                                                      !0
   16     5      > RETURN                                                       null

End of function add

Function remove:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  remove
number of ops:  5
compiled vars:  !0 = $game
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV                                                 !0      
   19     1        FETCH_OBJ_R                                          ~2      !0, 'name'
          2        FETCH_OBJ_UNSET                                      $1      'games'
          3        UNSET_DIM                                                    $1, ~2
   20     4      > RETURN                                                       null

End of function remove

Function getall:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  getAll
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   FETCH_OBJ_R                                          ~0      'games'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
   24     3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function getall

End of class GameCollection.

Class GameStore:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  __construct
number of ops:  7
compiled vars:  !0 = $games, !1 = $loans
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   RECV                                                 !0      
   30     1        RECV                                                 !1      
   29     2        ASSIGN_OBJ                                                   'games'
          3        OP_DATA                                                      !0
   30     4        ASSIGN_OBJ                                                   'loans'
          5        OP_DATA                                                      !1
   31     6      > RETURN                                                       null

End of function __construct

Function addgame:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  addGame
number of ops:  6
compiled vars:  !0 = $game
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   33     0  E >   RECV                                                 !0      
   34     1        FETCH_OBJ_R                                          ~1      'games'
          2        INIT_METHOD_CALL                                             ~1, 'add'
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0          
   35     5      > RETURN                                                       null

End of function addgame

Function getallgames:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  getAllGames
number of ops:  7
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   FETCH_OBJ_R                                          ~0      'games'
          1        INIT_METHOD_CALL                                             ~0, 'getAll'
          2        DO_FCALL                                          0  $1      
          3        VERIFY_RETURN_TYPE                                           $1
          4      > RETURN                                                       $1
   39     5*       VERIFY_RETURN_TYPE                                           
          6*     > RETURN                                                       null

End of function getallgames

Function checkout:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  checkOut
number of ops:  10
compiled vars:  !0 = $game
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   41     0  E >   RECV                                                 !0      
   42     1        FETCH_OBJ_R                                          ~1      'loans'
          2        INIT_METHOD_CALL                                             ~1, 'add'
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0          
   43     5        FETCH_OBJ_R                                          ~3      'games'
          6        INIT_METHOD_CALL                                             ~3, 'remove'
          7        SEND_VAR_EX                                                  !0
          8        DO_FCALL                                          0          
   44     9      > RETURN                                                       null

End of function checkout

Function checkin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  checkIn
number of ops:  10
compiled vars:  !0 = $game
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   RECV                                                 !0      
   47     1        FETCH_OBJ_R                                          ~1      'loans'
          2        INIT_METHOD_CALL                                             ~1, 'remove'
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0          
   48     5        FETCH_OBJ_R                                          ~3      'games'
          6        INIT_METHOD_CALL                                             ~3, 'add'
          7        SEND_VAR_EX                                                  !0
          8        DO_FCALL                                          0          
   49     9      > RETURN                                                       null

End of function checkin

Function getallonloan:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mehhI
function name:  getAllOnLoan
number of ops:  7
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   52     0  E >   FETCH_OBJ_R                                          ~0      'loans'
          1        INIT_METHOD_CALL                                             ~0, 'getAll'
          2        DO_FCALL                                          0  $1      
          3        VERIFY_RETURN_TYPE                                           $1
          4      > RETURN                                                       $1
   53     5*       VERIFY_RETURN_TYPE                                           
          6*     > RETURN                                                       null

End of function getallonloan

End of class GameStore.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.19 ms | 1110 KiB | 14 Q