3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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:  22
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   7     0  E >   NOP                                                      
  11     1        NOP                                                      
  15     2        NOP                                                      
  25     3        FETCH_CLASS                                   0  :3      'Bird'
         4        DECLARE_INHERITED_CLASS                          $4      'dove', $3
         5        ADD_INTERFACE                                            $4, 'CanFly'
         6        VERIFY_ABSTRACT_CLASS                                    $4
  32     7        FETCH_CLASS                                   0  :5      'Bird'
         8        DECLARE_INHERITED_CLASS                          $6      'penguin', $5
         9        ADD_INTERFACE                                            $6, 'CanSwim'
        10        VERIFY_ABSTRACT_CLASS                                    $6
  39    11        FETCH_CLASS                                   0  :7      'Bird'
        12        DECLARE_INHERITED_CLASS                          $8      'duck', $7
        13        ADD_INTERFACE                                            $8, 'CanFly'
        14        ADD_INTERFACE                                            $8, 'CanSwim'
        15        VERIFY_ABSTRACT_CLASS                                    $8
  52    16        NOP                                                      
  66    17        INIT_FCALL                                               'describe'
        18        SEND_VAL                                                 'Duck'
        19        DO_FCALL                                      0  $9      
        20        ECHO                                                     $9
        21      > 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                                       ~1      !0, 'Bird'
         2      > JMPZ                                                     ~1, ->14
  54     3    >   INIT_METHOD_CALL                                         !0, 'info'
         4        DO_FCALL                                      0          
  55     5        INSTANCEOF                                       ~3      !0, 'CanFly'
         6      > JMPZ                                                     ~3, ->9
  56     7    >   INIT_METHOD_CALL                                         !0, 'fly'
         8        DO_FCALL                                      0          
  58     9    >   INSTANCEOF                                       ~5      !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 >   FETCH_OBJ_R                                      $0      'name'
         1        ROPE_INIT                                     3  ~2      'I+am+a+'
         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 7.3.0