3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Visitor { public function visitCar(Car $car); public function visitGolf(Golf $golf); public function visitPorsche(Porsche $porsche); } interface Vehicle { public function accept(Visitor $v); } class Car implements Vehicle { public function accept(Visitor $v) { $v->visitCar($this); } } class Golf extends Car { public function accept(Visitor $v) { $v->visitGolf($this); } } class Porsche extends Car { public function accept(Visitor $v) { $v->visitPorsche($this); } } class DriveVisitor implements Visitor { public function visitCar(Car $car) { print 'Auto fährt' . PHP_EOL; } public function visitGolf(Golf $golf) { print 'Golf fährt schneller' . PHP_EOL; } public function visitPorsche(Porsche $porsche) { print 'Porsche fährt am schnellsten' . PHP_EOL; } } $c = new Car(); $g = new Golf(); $p = new Porsche(); $dv = new DriveVisitor(); $c->accept($dv); $g->accept($dv); $p->accept($dv);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  (null)
number of ops:  26
compiled vars:  !0 = $c, !1 = $g, !2 = $p, !3 = $dv
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   DECLARE_CLASS                                            'car'
   23     1        DECLARE_CLASS                                            'golf', 'car'
   31     2        DECLARE_CLASS                                            'porsche', 'car'
   39     3        DECLARE_CLASS                                            'drivevisitor'
   57     4        NEW                                              $4      'Car'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $4
   58     7        NEW                                              $7      'Golf'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $7
   59    10        NEW                                              $10     'Porsche'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $10
   61    13        NEW                                              $13     'DriveVisitor'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !3, $13
   63    16        INIT_METHOD_CALL                                         !0, 'accept'
         17        SEND_VAR_EX                                              !3
         18        DO_FCALL                                      0          
   64    19        INIT_METHOD_CALL                                         !1, 'accept'
         20        SEND_VAR_EX                                              !3
         21        DO_FCALL                                      0          
   65    22        INIT_METHOD_CALL                                         !2, 'accept'
         23        SEND_VAR_EX                                              !3
         24        DO_FCALL                                      0          
         25      > RETURN                                                   1

Class Visitor:
Function visitcar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  visitCar
number of ops:  2
compiled vars:  !0 = $car
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function visitcar

Function visitgolf:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  visitGolf
number of ops:  2
compiled vars:  !0 = $golf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function visitgolf

Function visitporsche:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  visitPorsche
number of ops:  2
compiled vars:  !0 = $porsche
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function visitporsche

End of class Visitor.

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

End of function accept

End of class Vehicle.

Class Car:
Function accept:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  accept
number of ops:  6
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        INIT_METHOD_CALL                                         !0, 'visitCar'
          2        FETCH_THIS                                       $1      
          3        SEND_VAR_EX                                              $1
          4        DO_FCALL                                      0          
   20     5      > RETURN                                                   null

End of function accept

End of class Car.

Class Golf:
Function accept:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  accept
number of ops:  6
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        INIT_METHOD_CALL                                         !0, 'visitGolf'
          2        FETCH_THIS                                       $1      
          3        SEND_VAR_EX                                              $1
          4        DO_FCALL                                      0          
   28     5      > RETURN                                                   null

End of function accept

End of class Golf.

Class Porsche:
Function accept:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  accept
number of ops:  6
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   35     1        INIT_METHOD_CALL                                         !0, 'visitPorsche'
          2        FETCH_THIS                                       $1      
          3        SEND_VAR_EX                                              $1
          4        DO_FCALL                                      0          
   36     5      > RETURN                                                   null

End of function accept

End of class Porsche.

Class DriveVisitor:
Function visitcar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  visitCar
number of ops:  3
compiled vars:  !0 = $car
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        ECHO                                                     'Auto+f%C3%A4hrt%0A'
   44     2      > RETURN                                                   null

End of function visitcar

Function visitgolf:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  visitGolf
number of ops:  3
compiled vars:  !0 = $golf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        ECHO                                                     'Golf+f%C3%A4hrt+schneller%0A'
   49     2      > RETURN                                                   null

End of function visitgolf

Function visitporsche:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u377m
function name:  visitPorsche
number of ops:  3
compiled vars:  !0 = $porsche
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   53     1        ECHO                                                     'Porsche+f%C3%A4hrt+am+schnellsten%0A'
   54     2      > RETURN                                                   null

End of function visitporsche

End of class DriveVisitor.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.49 ms | 1403 KiB | 13 Q