3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Food {} class AnimalFood extends Food {} abstract class Animal { protected string $name; public function __construct(string $name) { $this->name = $name; } public function eat(AnimalFood $food) { echo $this->name." nom noms ".get_class($food); } } class Cat extends Animal {} class Dog extends Animal { // The dog doesn't care if it's animal food, it'll eat ANY food public function eat(Food $food) { echo $this->name . " nom noms " . get_class($food); } } interface AnimalShelter { public function adopt(string $name): Animal; } class CatShelter implements AnimalShelter { public function adopt(string $name): Cat { return new Cat($name); } } class DogShelter implements AnimalShelter { public function adopt(string $name): Dog { return new Dog($name); } } $kitty = (new CatShelter)->adopt("Ricky"); $catFood = new AnimalFood(); $kitty->eat($catFood); echo "\n"; $doggy = (new DogShelter)->adopt("Mavrick"); $bananaPeel = new Food(); $doggy->eat($bananaPeel); echo "\n"; $kitty->eat($bananaPeel);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UkMYt
function name:  (null)
number of ops:  32
compiled vars:  !0 = $kitty, !1 = $catFood, !2 = $doggy, !3 = $bananaPeel
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   DECLARE_CLASS                                            'catshelter'
   45     1        DECLARE_CLASS                                            'dogshelter'
   54     2        NEW                                              $4      'CatShelter'
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $4, 'adopt'
          5        SEND_VAL_EX                                              'Ricky'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !0, $6
   55     8        NEW                                              $8      'AnimalFood'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $8
   56    11        INIT_METHOD_CALL                                         !0, 'eat'
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0          
   57    14        ECHO                                                     '%0A'
   59    15        NEW                                              $12     'DogShelter'
         16        DO_FCALL                                      0          
         17        INIT_METHOD_CALL                                         $12, 'adopt'
         18        SEND_VAL_EX                                              'Mavrick'
         19        DO_FCALL                                      0  $14     
         20        ASSIGN                                                   !2, $14
   60    21        NEW                                              $16     'Food'
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !3, $16
   61    24        INIT_METHOD_CALL                                         !2, 'eat'
         25        SEND_VAR_EX                                              !3
         26        DO_FCALL                                      0          
   62    27        ECHO                                                     '%0A'
   64    28        INIT_METHOD_CALL                                         !0, 'eat'
         29        SEND_VAR_EX                                              !3
         30        DO_FCALL                                      0          
         31      > RETURN                                                   1

Class Food: [no user functions]
Class AnimalFood: [no user functions]
Class Animal:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UkMYt
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   14     3      > RETURN                                                   null

End of function __construct

Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UkMYt
function name:  eat
number of ops:  7
compiled vars:  !0 = $food
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        FETCH_OBJ_R                                      ~1      'name'
          2        CONCAT                                           ~2      ~1, '+nom+noms+'
          3        GET_CLASS                                        ~3      !0
          4        CONCAT                                           ~4      ~2, ~3
          5        ECHO                                                     ~4
   19     6      > RETURN                                                   null

End of function eat

End of class Animal.

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

End of function __construct

Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UkMYt
function name:  eat
number of ops:  7
compiled vars:  !0 = $food
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        FETCH_OBJ_R                                      ~1      'name'
          2        CONCAT                                           ~2      ~1, '+nom+noms+'
          3        GET_CLASS                                        ~3      !0
          4        CONCAT                                           ~4      ~2, ~3
          5        ECHO                                                     ~4
   19     6      > RETURN                                                   null

End of function eat

End of class Cat.

Class Dog:
Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UkMYt
function name:  eat
number of ops:  7
compiled vars:  !0 = $food
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        FETCH_OBJ_R                                      ~1      'name'
          2        CONCAT                                           ~2      ~1, '+nom+noms+'
          3        GET_CLASS                                        ~3      !0
          4        CONCAT                                           ~4      ~2, ~3
          5        ECHO                                                     ~4
   29     6      > RETURN                                                   null

End of function eat

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

End of function __construct

End of class Dog.

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

End of function adopt

End of class AnimalShelter.

Class CatShelter:
Function adopt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UkMYt
function name:  adopt
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        NEW                                              $1      'Cat'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   42     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function adopt

End of class CatShelter.

Class DogShelter:
Function adopt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UkMYt
function name:  adopt
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   49     1        NEW                                              $1      'Dog'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   50     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function adopt

End of class DogShelter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.99 ms | 1403 KiB | 13 Q