3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface response { public function getResponseClass(); } class foo implements response { public $type = 'foo'; public function getResponseClass() { return 'hello'; } } class bar implements response { public $type = 'bar'; public function getResponseClass() { return 'world'; } } class hello { } class world { } class process { public function test1($a) { switch ($a->type) { case 'foo': return new hello(); case 'bar': return new world(); } } public function test2($a) { $class = $a->getResponseClass(); return new $class; } } $p = new process; var_dump($p->test1(new bar())); var_dump($p->test2(new bar()));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eroWj
function name:  (null)
number of ops:  22
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_CLASS                                            'foo'
   19     1        DECLARE_CLASS                                            'bar'
   60     2        NEW                                              $1      'process'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   61     5        INIT_FCALL                                               'var_dump'
          6        INIT_METHOD_CALL                                         !0, 'test1'
          7        NEW                                              $4      'bar'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $4
         10        DO_FCALL                                      0  $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                                 
   62    13        INIT_FCALL                                               'var_dump'
         14        INIT_METHOD_CALL                                         !0, 'test2'
         15        NEW                                              $8      'bar'
         16        DO_FCALL                                      0          
         17        SEND_VAR_NO_REF_EX                                       $8
         18        DO_FCALL                                      0  $10     
         19        SEND_VAR                                                 $10
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

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

End of function getresponseclass

End of class response.

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

End of function getresponseclass

End of class foo.

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

End of function getresponseclass

End of class bar.

Class hello: [no user functions]
Class world: [no user functions]
Class process:
Function test1:
Finding entry points
Branch analysis from position: 0
4 jumps found. (Code = 188) Position 1 = 8, Position 2 = 12, Position 3 = 16, Position 4 = 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 12
Branch analysis from position: 8
filename:       /in/eroWj
function name:  test1
number of ops:  18
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        FETCH_OBJ_R                                      ~1      !0, 'type'
          2      > SWITCH_STRING                                            ~1, [ 'foo':->8, 'bar':->12, ], ->16
   45     3    >   CASE                                                     ~1, 'foo'
          4      > JMPNZ                                                    ~2, ->8
   47     5    >   CASE                                                     ~1, 'bar'
          6      > JMPNZ                                                    ~2, ->12
          7    > > JMP                                                      ->16
   46     8    >   NEW                                              $3      'hello'
          9        DO_FCALL                                      0          
         10        FREE                                                     ~1
         11      > RETURN                                                   $3
   48    12    >   NEW                                              $5      'world'
         13        DO_FCALL                                      0          
         14        FREE                                                     ~1
         15      > RETURN                                                   $5
         16    >   FREE                                                     ~1
   51    17      > RETURN                                                   null

End of function test1

Function test2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eroWj
function name:  test2
number of ops:  9
compiled vars:  !0 = $a, !1 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   55     1        INIT_METHOD_CALL                                         !0, 'getResponseClass'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !1, $2
   56     4        FETCH_CLASS                                   0  $4      !1
          5        NEW                                              $5      $4
          6        DO_FCALL                                      0          
          7      > RETURN                                                   $5
   57     8*     > RETURN                                                   null

End of function test2

End of class process.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.65 ms | 1400 KiB | 15 Q