3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Visitor { public final function __call(string $method, array $args) { if ($method === 'visit') { $class = substr(strrchr(static::class, '\\'), 1); $method .= $class; die(static::class); if (method_exists($this, $method)) { return call_user_func_array([$this, $method], $args); } } throw new Exception('Unknown method ' . $method); } } interface Visitable { public function accept(Visitor $v); } class FooVisitor extends Visitor { public function visitFoo(Foo $foo) { print 'visit Foo' . PHP_EOL; } } class Foo implements Visitable { public function accept(Visitor $v) { $v->visit($this); } } $fv = new FooVisitor(); $f = new Foo(); $f->accept($fv);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n2iJ0
function name:  (null)
number of ops:  11
compiled vars:  !0 = $fv, !1 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   DECLARE_CLASS                                            'foo'
   41     1        NEW                                              $2      'FooVisitor'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   42     4        NEW                                              $5      'Foo'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $5
   43     7        INIT_METHOD_CALL                                         !1, 'accept'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
         10      > RETURN                                                   1

Class Visitor:
Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 31
Branch analysis from position: 4
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/n2iJ0
function name:  __call
number of ops:  37
compiled vars:  !0 = $method, !1 = $args, !2 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        IS_IDENTICAL                                             !0, 'visit'
          3      > JMPZ                                                     ~3, ->31
    8     4    >   INIT_FCALL                                               'substr'
          5        INIT_FCALL                                               'strrchr'
          6        FETCH_CLASS_NAME                                 ~4      
          7        SEND_VAL                                                 ~4
          8        SEND_VAL                                                 '%5C'
          9        DO_ICALL                                         $5      
         10        SEND_VAR                                                 $5
         11        SEND_VAL                                                 1
         12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !2, $6
    9    14        ASSIGN_OP                                     8          !0, !2
   10    15        FETCH_CLASS_NAME                                 ~9      
         16      > EXIT                                                     ~9
   11    17*       INIT_FCALL                                               'method_exists'
         18*       FETCH_THIS                                       ~10     
         19*       SEND_VAL                                                 ~10
         20*       SEND_VAR                                                 !0
         21*       DO_ICALL                                         $11     
         22*       JMPZ                                                     $11, ->31
   12    23*       FETCH_THIS                                       ~12     
         24*       INIT_ARRAY                                       ~13     ~12
         25*       ADD_ARRAY_ELEMENT                                ~13     !0
         26*       INIT_USER_CALL                                0          'call_user_func_array', ~13
         27*       SEND_ARRAY                                               !1
         28*       CHECK_UNDEF_ARGS                                         
         29*       DO_FCALL                                      0  $14     
         30*       RETURN                                                   $14
   16    31    >   NEW                                              $15     'Exception'
         32        CONCAT                                           ~16     'Unknown+method+', !0
         33        SEND_VAL_EX                                              ~16
         34        DO_FCALL                                      0          
         35      > THROW                                         0          $15
   17    36*     > RETURN                                                   null

End of function __call

End of class Visitor.

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

End of function accept

End of class Visitable.

Class FooVisitor:
Function visitfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n2iJ0
function name:  visitFoo
number of ops:  3
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        ECHO                                                     'visit+Foo%0A'
   30     2      > RETURN                                                   null

End of function visitfoo

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 31
Branch analysis from position: 4
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/n2iJ0
function name:  __call
number of ops:  37
compiled vars:  !0 = $method, !1 = $args, !2 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        IS_IDENTICAL                                             !0, 'visit'
          3      > JMPZ                                                     ~3, ->31
    8     4    >   INIT_FCALL                                               'substr'
          5        INIT_FCALL                                               'strrchr'
          6        FETCH_CLASS_NAME                                 ~4      
          7        SEND_VAL                                                 ~4
          8        SEND_VAL                                                 '%5C'
          9        DO_ICALL                                         $5      
         10        SEND_VAR                                                 $5
         11        SEND_VAL                                                 1
         12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !2, $6
    9    14        ASSIGN_OP                                     8          !0, !2
   10    15        FETCH_CLASS_NAME                                 ~9      
         16      > EXIT                                                     ~9
   11    17*       INIT_FCALL                                               'method_exists'
         18*       FETCH_THIS                                       ~10     
         19*       SEND_VAL                                                 ~10
         20*       SEND_VAR                                                 !0
         21*       DO_ICALL                                         $11     
         22*       JMPZ                                                     $11, ->31
   12    23*       FETCH_THIS                                       ~12     
         24*       INIT_ARRAY                                       ~13     ~12
         25*       ADD_ARRAY_ELEMENT                                ~13     !0
         26*       INIT_USER_CALL                                0          'call_user_func_array', ~13
         27*       SEND_ARRAY                                               !1
         28*       CHECK_UNDEF_ARGS                                         
         29*       DO_FCALL                                      0  $14     
         30*       RETURN                                                   $14
   16    31    >   NEW                                              $15     'Exception'
         32        CONCAT                                           ~16     'Unknown+method+', !0
         33        SEND_VAL_EX                                              ~16
         34        DO_FCALL                                      0          
         35      > THROW                                         0          $15
   17    36*     > RETURN                                                   null

End of function __call

End of class FooVisitor.

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

End of function accept

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.06 ms | 1404 KiB | 19 Q