3v4l.org

run code in 300+ PHP versions simultaneously
<?php // How to check a variable to see if it can be called // as a function. // // Simple variable containing a function // function someFunction() { } $functionVariable = 'someFunction'; var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true) echo $callable_name, "\n"; // someFunction // // Array containing a method // class someClass { function someMethod() { } } $anObject = new someClass(); $methodVariable = array($anObject, 'someMethod'); var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true) echo $callable_name, "\n"; // someClass::someMethod
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RuiTa
function name:  (null)
number of ops:  28
compiled vars:  !0 = $functionVariable, !1 = $callable_name, !2 = $anObject, !3 = $methodVariable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, 'someFunction'
   15     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'is_callable'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 <false>
          5        SEND_REF                                                 !1
          6        DO_ICALL                                         $5      
          7        SEND_VAR                                                 $5
          8        DO_ICALL                                                 
   17     9        ECHO                                                     !1
         10        ECHO                                                     '%0A'
   31    11        NEW                                              $7      'someClass'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !2, $7
   33    14        INIT_ARRAY                                       ~10     !2
         15        ADD_ARRAY_ELEMENT                                ~10     'someMethod'
         16        ASSIGN                                                   !3, ~10
   35    17        INIT_FCALL                                               'var_dump'
         18        INIT_FCALL                                               'is_callable'
         19        SEND_VAR                                                 !3
         20        SEND_VAL                                                 <true>
         21        SEND_REF                                                 !1
         22        DO_ICALL                                         $12     
         23        SEND_VAR                                                 $12
         24        DO_ICALL                                                 
   37    25        ECHO                                                     !1
         26        ECHO                                                     '%0A'
         27      > RETURN                                                   1

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

End of function somefunction

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

End of function somemethod

End of class someClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.01 ms | 1396 KiB | 17 Q