3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_class_name($class) { if (is_object($class)) { return get_class_name(get_class($class)); } else if (is_string($class)) { if (strpos('\\', $class) !== false) { return substr(strrchr($class, '\\'), 1); } return $class; } return false; } abstract class Visitor { public final function __call(string $method, array $args) { if ($method === 'visit') { $method .= get_class_name(static::class); die($method); 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/NQdv0
function name:  (null)
number of ops:  11
compiled vars:  !0 = $fv, !1 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   DECLARE_CLASS                                            'foo'
   55     1        NEW                                              $2      'FooVisitor'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   56     4        NEW                                              $5      'Foo'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $5
   57     7        INIT_METHOD_CALL                                         !1, 'accept'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
         10      > RETURN                                                   1

Function get_class_name:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NQdv0
function name:  get_class_name
number of ops:  29
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        TYPE_CHECK                                  256          !0
          2      > JMPZ                                                     ~1, ->9
    6     3    >   INIT_FCALL_BY_NAME                                       'get_class_name'
          4        GET_CLASS                                        ~2      !0
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
          8*       JMP                                                      ->27
    7     9    >   TYPE_CHECK                                   64          !0
         10      > JMPZ                                                     ~4, ->27
    8    11    >   INIT_FCALL                                               'strpos'
         12        SEND_VAL                                                 '%5C'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $5      
         15        TYPE_CHECK                                  1018          $5
         16      > JMPZ                                                     ~6, ->26
    9    17    >   INIT_FCALL                                               'substr'
         18        INIT_FCALL                                               'strrchr'
         19        SEND_VAR                                                 !0
         20        SEND_VAL                                                 '%5C'
         21        DO_ICALL                                         $7      
         22        SEND_VAR                                                 $7
         23        SEND_VAL                                                 1
         24        DO_ICALL                                         $8      
         25      > RETURN                                                   $8
   12    26    > > RETURN                                                   !0
   15    27    > > RETURN                                                   <false>
   16    28*     > RETURN                                                   null

End of function get_class_name

Class Visitor:
Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/NQdv0
function name:  __call
number of ops:  30
compiled vars:  !0 = $method, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        IS_IDENTICAL                                             !0, 'visit'
          3      > JMPZ                                                     ~2, ->24
   23     4    >   INIT_FCALL                                               'get_class_name'
          5        FETCH_CLASS_NAME                                 ~3      
          6        SEND_VAL                                                 ~3
          7        DO_FCALL                                      0  $4      
          8        ASSIGN_OP                                     8          !0, $4
   24     9      > EXIT                                                     !0
   25    10*       INIT_FCALL                                               'method_exists'
         11*       FETCH_THIS                                       ~6      
         12*       SEND_VAL                                                 ~6
         13*       SEND_VAR                                                 !0
         14*       DO_ICALL                                         $7      
         15*       JMPZ                                                     $7, ->24
   26    16*       FETCH_THIS                                       ~8      
         17*       INIT_ARRAY                                       ~9      ~8
         18*       ADD_ARRAY_ELEMENT                                ~9      !0
         19*       INIT_USER_CALL                                0          'call_user_func_array', ~9
         20*       SEND_ARRAY                                               !1
         21*       CHECK_UNDEF_ARGS                                         
         22*       DO_FCALL                                      0  $10     
         23*       RETURN                                                   $10
   30    24    >   NEW                                              $11     'Exception'
         25        CONCAT                                           ~12     'Unknown+method+', !0
         26        SEND_VAL_EX                                              ~12
         27        DO_FCALL                                      0          
         28      > THROW                                         0          $11
   31    29*     > 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/NQdv0
function name:  accept
number of ops:  2
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     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/NQdv0
function name:  visitFoo
number of ops:  3
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        ECHO                                                     'visit+Foo%0A'
   44     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 = 24
Branch analysis from position: 4
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/NQdv0
function name:  __call
number of ops:  30
compiled vars:  !0 = $method, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        IS_IDENTICAL                                             !0, 'visit'
          3      > JMPZ                                                     ~2, ->24
   23     4    >   INIT_FCALL                                               'get_class_name'
          5        FETCH_CLASS_NAME                                 ~3      
          6        SEND_VAL                                                 ~3
          7        DO_FCALL                                      0  $4      
          8        ASSIGN_OP                                     8          !0, $4
   24     9      > EXIT                                                     !0
   25    10*       INIT_FCALL                                               'method_exists'
         11*       FETCH_THIS                                       ~6      
         12*       SEND_VAL                                                 ~6
         13*       SEND_VAR                                                 !0
         14*       DO_ICALL                                         $7      
         15*       JMPZ                                                     $7, ->24
   26    16*       FETCH_THIS                                       ~8      
         17*       INIT_ARRAY                                       ~9      ~8
         18*       ADD_ARRAY_ELEMENT                                ~9      !0
         19*       INIT_USER_CALL                                0          'call_user_func_array', ~9
         20*       SEND_ARRAY                                               !1
         21*       CHECK_UNDEF_ARGS                                         
         22*       DO_FCALL                                      0  $10     
         23*       RETURN                                                   $10
   30    24    >   NEW                                              $11     'Exception'
         25        CONCAT                                           ~12     'Unknown+method+', !0
         26        SEND_VAL_EX                                              ~12
         27        DO_FCALL                                      0          
         28      > THROW                                         0          $11
   31    29*     > 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/NQdv0
function name:  accept
number of ops:  6
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   51     1        INIT_METHOD_CALL                                         !0, 'visit'
          2        FETCH_THIS                                       $1      
          3        SEND_VAR_EX                                              $1
          4        DO_FCALL                                      0          
   52     5      > RETURN                                                   null

End of function accept

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.29 ms | 1415 KiB | 23 Q