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 static function adopt(string $name): Animal; } class CatShelter implements AnimalShelter { public static function adopt(string $name): Cat { return new Cat($name); } } class DogShelter implements AnimalShelter { public static function adopt(string $name): Dog { return new Dog($name); } } $kitty = CatShelter::adopt("Ricky"); $catFood = new AnimalFood(); $kitty->eat($catFood); echo "\n"; $doggy = 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/7gbFQ
function name:  (null)
number of ops:  28
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        INIT_STATIC_METHOD_CALL                                  'CatShelter', 'adopt'
          3        SEND_VAL_EX                                              'Ricky'
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !0, $4
   55     6        NEW                                              $6      'AnimalFood'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   56     9        INIT_METHOD_CALL                                         !0, 'eat'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
   57    12        ECHO                                                     '%0A'
   59    13        INIT_STATIC_METHOD_CALL                                  'DogShelter', 'adopt'
         14        SEND_VAL_EX                                              'Mavrick'
         15        DO_FCALL                                      0  $10     
         16        ASSIGN                                                   !2, $10
   60    17        NEW                                              $12     'Food'
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !3, $12
   61    20        INIT_METHOD_CALL                                         !2, 'eat'
         21        SEND_VAR_EX                                              !3
         22        DO_FCALL                                      0          
   62    23        ECHO                                                     '%0A'
   64    24        INIT_METHOD_CALL                                         !0, '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/7gbFQ
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/7gbFQ
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/7gbFQ
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/7gbFQ
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/7gbFQ
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/7gbFQ
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/7gbFQ
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/7gbFQ
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/7gbFQ
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:
169.09 ms | 1403 KiB | 13 Q