3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Food { public function consume() { } } class AnimalFood extends Food { } abstract class Animal { protected string $name; public function __construct(string $name) { $this->name = $name; } abstract public function speak(); public function eat(AnimalFood $food) { $food->consume(); } } class Dog extends Animal { public function speak() { echo "woof"; } /* * The dog doesn't care if it's animal food, it'll eat ANY food */ public function eat(Food $food) { $food->consume(); } } class Cat extends Animal { public function speak() { echo "meow"; } } 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"); $kitty->speak();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GvK1N
function name:  (null)
number of ops:  9
compiled vars:  !0 = $kitty
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   DECLARE_CLASS                                            'catshelter'
   61     1        DECLARE_CLASS                                            'dogshelter'
   69     2        INIT_STATIC_METHOD_CALL                                  'CatShelter', 'adopt'
          3        SEND_VAL_EX                                              'Ricky'
          4        DO_FCALL                                      0  $1      
          5        ASSIGN                                                   !0, $1
   70     6        INIT_METHOD_CALL                                         !0, 'speak'
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

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

End of function consume

End of class Food.

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

End of function consume

End of class AnimalFood.

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

End of function __construct

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

End of function speak

Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GvK1N
function name:  eat
number of ops:  4
compiled vars:  !0 = $food
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        INIT_METHOD_CALL                                         !0, 'consume'
          2        DO_FCALL                                      0          
   25     3      > RETURN                                                   null

End of function eat

End of class Animal.

Class Dog:
Function speak:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GvK1N
function name:  speak
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ECHO                                                     'woof'
   31     1      > RETURN                                                   null

End of function speak

Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GvK1N
function name:  eat
number of ops:  4
compiled vars:  !0 = $food
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        INIT_METHOD_CALL                                         !0, 'consume'
          2        DO_FCALL                                      0          
   38     3      > 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/GvK1N
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   19     3      > RETURN                                                   null

End of function __construct

End of class Dog.

Class Cat:
Function speak:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GvK1N
function name:  speak
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   ECHO                                                     'meow'
   44     1      > RETURN                                                   null

End of function speak

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GvK1N
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   19     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/GvK1N
function name:  eat
number of ops:  4
compiled vars:  !0 = $food
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        INIT_METHOD_CALL                                         !0, 'consume'
          2        DO_FCALL                                      0          
   25     3      > RETURN                                                   null

End of function eat

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/GvK1N
function name:  adopt
number of ops:  3
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     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/GvK1N
function name:  adopt
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   56     1        NEW                                              $1      'Cat'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   57     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/GvK1N
function name:  adopt
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
   65     1        NEW                                              $1      'Dog'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   66     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:
136.02 ms | 1004 KiB | 13 Q