3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { function getKey() { return 1; } }; class Bar { function getId() { return 2; } }; class Repo { function getItems($id) { return ['got' => $id]; } } class Test { private Repo $repository; function __construct() { $this->repository = new Repo(); } function foo(Foo|Bar $obj): array { return $this->repository->getItems( match ($obj::class) { Foo::class => $obj->getKey(), Bar::class=> $obj->getId(), } ); } }; $obj = new Foo(); $test = new Test(); var_dump($test->foo($obj));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t9cKQ
function name:  (null)
number of ops:  13
compiled vars:  !0 = $obj, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   NEW                                              $2      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   39     3        NEW                                              $5      'Test'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   40     6        INIT_FCALL                                               'var_dump'
          7        INIT_METHOD_CALL                                         !1, 'foo'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $8      
         10        SEND_VAR                                                 $8
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

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

End of function getkey

End of class Foo.

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

End of function getid

End of class Bar.

Class Repo:
Function getitems:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t9cKQ
function name:  getItems
number of ops:  4
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        INIT_ARRAY                                       ~1      !0, 'got'
          2      > RETURN                                                   ~1
   17     3*     > RETURN                                                   null

End of function getitems

End of class Repo.

Class Test:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t9cKQ
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   NEW                                              $1      'Repo'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'repository'
          3        OP_DATA                                                  $1
   25     4      > RETURN                                                   null

End of function __construct

Function foo:
Finding entry points
Branch analysis from position: 0
3 jumps found. (Code = 195) Position 1 = 6, Position 2 = 10, Position 3 = 5
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 5
1 jumps found. (Code = 197) Position 1 = -2
filename:       /in/t9cKQ
function name:  foo
number of ops:  21
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        FETCH_OBJ_R                                      ~1      'repository'
          2        INIT_METHOD_CALL                                         ~1, 'getItems'
   29     3        FETCH_CLASS_NAME                                 ~2      !0
          4      > MATCH                                                    ~2, [ 'Foo':->6, 'Bar':->10, ], ->5
          5    > > MATCH_ERROR                                              ~2
   30     6    >   INIT_METHOD_CALL                                         !0, 'getKey'
          7        DO_FCALL                                      0  $4      
          8        QM_ASSIGN                                        ~5      $4
          9      > JMP                                                      ->14
   31    10    >   INIT_METHOD_CALL                                         !0, 'getId'
         11        DO_FCALL                                      0  $6      
         12        QM_ASSIGN                                        ~5      $6
         13      > JMP                                                      ->14
         14    >   FREE                                                     ~2
         15        SEND_VAL_EX                                              ~5
   28    16        DO_FCALL                                      0  $7      
   31    17        VERIFY_RETURN_TYPE                                       $7
         18      > RETURN                                                   $7
   34    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function foo

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
128.81 ms | 1015 KiB | 14 Q