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 $this->name . " barks"; } /* * 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 $this->name . " meows"; } } 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(); echo "\n"; $doggy = DogShelter::adopt("Mavrick"); $doggy->speak();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rgPP2
function name:  (null)
number of ops:  16
compiled vars:  !0 = $kitty, !1 = $doggy
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  $2      
          5        ASSIGN                                                   !0, $2
   70     6        INIT_METHOD_CALL                                         !0, 'speak'
          7        DO_FCALL                                      0          
   71     8        ECHO                                                     '%0A'
   73     9        INIT_STATIC_METHOD_CALL                                  'DogShelter', 'adopt'
         10        SEND_VAL_EX                                              'Mavrick'
         11        DO_FCALL                                      0  $5      
         12        ASSIGN                                                   !1, $5
   74    13        INIT_METHOD_CALL                                         !1, 'speak'
         14        DO_FCALL                                      0          
         15      > RETURN                                                   1

Class Food:
Function consume:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rgPP2
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/rgPP2
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/rgPP2
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/rgPP2
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/rgPP2
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/rgPP2
function name:  speak
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1        CONCAT                                           ~1      ~0, '+barks'
          2        ECHO                                                     ~1
   31     3      > 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/rgPP2
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/rgPP2
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/rgPP2
function name:  speak
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1        CONCAT                                           ~1      ~0, '+meows'
          2        ECHO                                                     ~1
   44     3      > 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/rgPP2
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/rgPP2
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/rgPP2
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/rgPP2
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/rgPP2
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:
161.02 ms | 1407 KiB | 13 Q