3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * An example of duck typing in PHP */ interface CanFly { public function fly(); } interface CanSwim { public function swim(); } class Bird { public function info() { echo "I am a {$this->name}\n"; echo "I am an bird\n"; } } /** * some implementations of birds */ class Dove extends Bird implements CanFly { var $name = "Dove"; public function fly() { echo "I fly\n"; } } class Penguin extends Bird implements CanSwim { var $name = "Penguin"; public function swim() { echo "I swim\n"; } } class Duck extends Bird implements CanFly, CanSwim { var $name = "Duck"; public function fly() { echo "I fly\n"; } public function swim() { echo "I swim\n"; } } /** * a simple function to describe a bird */ function describe($bird) { if ($bird instanceof Bird) { $bird->info(); if ($bird instanceof CanFly) { $bird->fly(); } if ($bird instanceof CanSwim) { $bird->swim(); } } else { die("This is not a bird. I cannot describe it."); } } echo describe("Duck");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/La5F9
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   DECLARE_CLASS                                            'dove', 'bird'
   32     1        DECLARE_CLASS                                            'penguin', 'bird'
   39     2        DECLARE_CLASS                                            'duck', 'bird'
   66     3        INIT_FCALL                                               'describe'
          4        SEND_VAL                                                 'Duck'
          5        DO_FCALL                                      0  $0      
          6        ECHO                                                     $0
          7      > RETURN                                                   1

Function describe:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 9
Branch analysis from position: 14
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/La5F9
function name:  describe
number of ops:  16
compiled vars:  !0 = $bird
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   53     1        INSTANCEOF                                               !0, 'Bird'
          2      > JMPZ                                                     ~1, ->14
   54     3    >   INIT_METHOD_CALL                                         !0, 'info'
          4        DO_FCALL                                      0          
   55     5        INSTANCEOF                                               !0, 'CanFly'
          6      > JMPZ                                                     ~3, ->9
   56     7    >   INIT_METHOD_CALL                                         !0, 'fly'
          8        DO_FCALL                                      0          
   58     9    >   INSTANCEOF                                               !0, 'CanSwim'
         10      > JMPZ                                                     ~5, ->13
   59    11    >   INIT_METHOD_CALL                                         !0, 'swim'
         12        DO_FCALL                                      0          
         13    > > JMP                                                      ->15
   62    14    > > EXIT                                                     'This+is+not+a+bird.+I+cannot+describe+it.'
   64    15    > > RETURN                                                   null

End of function describe

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

End of function fly

End of class CanFly.

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

End of function swim

End of class CanSwim.

Class Bird:
Function info:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/La5F9
function name:  info
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ROPE_INIT                                     3  ~2      'I+am+a+'
          1        FETCH_OBJ_R                                      ~0      'name'
          2        ROPE_ADD                                      1  ~2      ~2, ~0
          3        ROPE_END                                      2  ~1      ~2, '%0A'
          4        ECHO                                                     ~1
   18     5        ECHO                                                     'I+am+an+bird%0A'
   19     6      > RETURN                                                   null

End of function info

End of class Bird.

Class Dove:
Function fly:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/La5F9
function name:  fly
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ECHO                                                     'I+fly%0A'
   29     1      > RETURN                                                   null

End of function fly

End of class Dove.

Class Penguin:
Function swim:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/La5F9
function name:  swim
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ECHO                                                     'I+swim%0A'
   36     1      > RETURN                                                   null

End of function swim

End of class Penguin.

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

End of function fly

Function swim:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/La5F9
function name:  swim
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   ECHO                                                     'I+swim%0A'
   46     1      > RETURN                                                   null

End of function swim

End of class Duck.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.36 ms | 1403 KiB | 14 Q