3v4l.org

run code in 500+ 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 . " eats " . get_class($food); } } class Dog extends Animal { public function eat(Food $food) { echo $this->name . " eats " . get_class($food); } } class Cat extends Animal { public function eat(Food $food) { echo $this->name . " eats " . get_class($food); } } interface AnimalShelter { public function adopt(string $name): Animal; } class CatShelter implements AnimalShelter { public function adopt(string $name): Cat // instead of returning class type Animal, it can return class type Cat { return new Cat($name); } } class DogShelter implements AnimalShelter { public function adopt(string $name): Dog // instead of returning class type Animal, it can return class type Dog { return new Dog($name); } } $kitty = (new CatShelter)->adopt("Ricky"); $catFood = new AnimalFood(); $kitty->eat($catFood); echo "\n"; $doggy = (new DogShelter)->adopt("Mavrick"); $banana = new Food(); $doggy->eat($banana);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/14rTK
function name:  (null)
number of ops:  28
compiled vars:  !0 = $kitty, !1 = $catFood, !2 = $doggy, !3 = $banana
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   40     0  E >   DECLARE_CLASS                                                'catshelter'
   48     1        DECLARE_CLASS                                                'dogshelter'
   57     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
   58     8        NEW                                                  $8      'AnimalFood'
          9        DO_FCALL                                          0          
         10        ASSIGN                                                       !1, $8
   59    11        INIT_METHOD_CALL                                             !0, 'eat'
         12        SEND_VAR_EX                                                  !1
         13        DO_FCALL                                          0          
   60    14        ECHO                                                         '%0A'
   62    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
   63    21        NEW                                                  $16     'Food'
         22        DO_FCALL                                          0          
         23        ASSIGN                                                       !3, $16
   64    24        INIT_METHOD_CALL                                             !2, 'eat'
         25        SEND_VAR_EX                                                  !3
         26        DO_FCALL                                          0          
         27      > 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/14rTK
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/14rTK
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, '+eats+'
          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 Dog:
Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/14rTK
function name:  eat
number of ops:  7
compiled vars:  !0 = $food
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
   25     1        FETCH_OBJ_R                                          ~1      'name'
          2        CONCAT                                               ~2      ~1, '+eats+'
          3        GET_CLASS                                            ~3      !0
          4        CONCAT                                               ~4      ~2, ~3
          5        ECHO                                                         ~4
   26     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/14rTK
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 Cat:
Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/14rTK
function name:  eat
number of ops:  7
compiled vars:  !0 = $food
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   RECV                                                 !0      
   32     1        FETCH_OBJ_R                                          ~1      'name'
          2        CONCAT                                               ~2      ~1, '+eats+'
          3        GET_CLASS                                            ~3      !0
          4        CONCAT                                               ~4      ~2, ~3
          5        ECHO                                                         ~4
   33     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/14rTK
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 Cat.

Class AnimalShelter:
Function adopt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/14rTK
function name:  adopt
number of ops:  3
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     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/14rTK
function name:  adopt
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   42     0  E >   RECV                                                 !0      
   44     1        NEW                                                  $1      'Cat'
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0          
          4        VERIFY_RETURN_TYPE                                           $1
          5      > RETURN                                                       $1
   45     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/14rTK
function name:  adopt
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   50     0  E >   RECV                                                 !0      
   52     1        NEW                                                  $1      'Dog'
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0          
          4        VERIFY_RETURN_TYPE                                           $1
          5      > RETURN                                                       $1
   53     6*       VERIFY_RETURN_TYPE                                           
          7*     > RETURN                                                       null

End of function adopt

End of class DogShelter.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
154.82 ms | 1544 KiB | 8 Q