3v4l.org

run code in 500+ PHP versions simultaneously
<?php function reflectCallable($arg): ReflectionFunctionAbstract { if (is_array($arg)) { $ref = new ReflectionMethod(...$arg); } elseif (is_callable($arg)) { $ref = new ReflectionFunction($arg); } return $ref; } function definedFunc(Foo $foo) {} $callable = function(Foo $foo) {}; class Bar { public function baz(Foo $foo) {} } foreach (['definedFunc', $callable, ['Bar', 'baz']] as $callable) { $reflected = reflectCallable($callable); if ((string) $reflected->getParameters()[0]->getType() === 'Foo') { echo 'Callable takes Foo', PHP_EOL; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/c5vmM
function name:  (null)
number of ops:  24
compiled vars:  !0 = $callable, !1 = $reflected
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   DECLARE_LAMBDA_FUNCTION                              ~2      [0]
          1        ASSIGN                                                       !0, ~2
   16     2        INIT_ARRAY                                           ~4      'definedFunc'
          3        ADD_ARRAY_ELEMENT                                    ~4      !0
          4        ADD_ARRAY_ELEMENT                                    ~4      <array>
          5      > FE_RESET_R                                           $5      ~4, ->22
          6    > > FE_FETCH_R                                                   $5, !0, ->22
   17     7    >   INIT_FCALL                                                   'reflectcallable'
          8        SEND_VAR                                                     !0
          9        DO_FCALL                                          0  $6      
         10        ASSIGN                                                       !1, $6
   19    11        INIT_METHOD_CALL                                             !1, 'getParameters'
         12        DO_FCALL                                          0  $8      
         13        FETCH_DIM_R                                          ~9      $8, 0
         14        INIT_METHOD_CALL                                             ~9, 'getType'
         15        DO_FCALL                                          0  $10     
         16        CAST                                              6  ~11     $10
         17        IS_IDENTICAL                                                 ~11, 'Foo'
         18      > JMPZ                                                         ~12, ->21
   20    19    >   ECHO                                                         'Callable+takes+Foo'
         20        ECHO                                                         '%0A'
   16    21    > > JMP                                                          ->6
         22    >   FE_FREE                                                      $5
   22    23      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c5vmM
function name:  {closure:/in/c5vmM:13}
number of ops:  2
compiled vars:  !0 = $foo
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1      > RETURN                                                       null

End of Dynamic Function 0

Function reflectcallable:
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 = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/c5vmM
function name:  reflectCallable
number of ops:  21
compiled vars:  !0 = $arg, !1 = $ref
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
    3     1        TYPE_CHECK                                      128          !0
          2      > JMPZ                                                         ~2, ->9
    4     3    >   NEW                                                  $3      'ReflectionMethod'
          4        SEND_UNPACK                                                  !0
          5        CHECK_UNDEF_ARGS                                             
          6        DO_FCALL                                          1          
          7        ASSIGN                                                       !1, $3
    3     8      > JMP                                                          ->17
    5     9    >   INIT_FCALL                                                   'is_callable'
         10        SEND_VAR                                                     !0
         11        DO_ICALL                                             $6      
         12      > JMPZ                                                         $6, ->17
    6    13    >   NEW                                                  $7      'ReflectionFunction'
         14        SEND_VAR_EX                                                  !0
         15        DO_FCALL                                          0          
         16        ASSIGN                                                       !1, $7
    9    17    >   VERIFY_RETURN_TYPE                                           !1
         18      > RETURN                                                       !1
   10    19*       VERIFY_RETURN_TYPE                                           
         20*     > RETURN                                                       null

End of function reflectcallable

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

End of function definedfunc

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

End of function baz

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
237.84 ms | 2220 KiB | 15 Q