3v4l.org

run code in 200+ PHP versions simultaneously
<?php // An example callback function function my_callback_function() { echo 'hello world!', PHP_EOL; } // Callback methods in classes class ParentClass { static function myCallbackMethod() { echo 'Hello Parent!', PHP_EOL; } } class MyClass extends ParentClass { static function myCallbackMethod() { echo 'Hello Child!', PHP_EOL; } } class Invokable { public function __invoke() { echo 'Hello Invokable', PHP_EOL; } } $obj = new MyClass(); $invokable = new Invokable(); $callbacks = array( 'type1' => 'my_callback_function', 'type2' => array('MyClass', 'myCallbackMethod'), 'type3' => array($obj, 'myCallbackMethod'), 'type6' => $invokable, 'type7' => function() { echo 'Hello Closure', PHP_EOL; }, 'type4' => 'MyClass::myCallbackMethod', 'type5' => array('MyClass', 'parent::myCallbackMethod'), ); foreach( $callbacks as $key => $callback ) { echo PHP_EOL, 'Testing ', $key, PHP_EOL; var_dump(is_callable()); call_user_func($callback); try { $callback(); } catch( Error $e ) { echo $e->getMessage(), PHP_EOL; } }
based on VfmVa
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 40
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 40
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Found catch point at position: 34
Branch analysis from position: 34
2 jumps found. (Code = 107) Position 1 = 35, Position 2 = -2
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
filename:       /in/CrEev
function name:  (null)
number of ops:  42
compiled vars:  !0 = $obj, !1 = $invokable, !2 = $callbacks, !3 = $callback, !4 = $key, !5 = $e
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  27     0  E >   NEW                                              $6      :79
         1        DO_FCALL                                      0          
         2        QM_ASSIGN                                                !0
  28     3        NEW                                              $9      :75
         4        DO_FCALL                                      0          
         5        QM_ASSIGN                                                !1
  31     6        INIT_ARRAY                                       ~12     'my_callback_function', 'type1'
         7        ADD_ARRAY_ELEMENT                                ~12     <array>, 'type2'
  33     8        INIT_ARRAY                                       ~13     !0
         9        ADD_ARRAY_ELEMENT                                ~13     'myCallbackMethod'
        10        ADD_ARRAY_ELEMENT                                ~12     ~13, 'type3'
  34    11        ADD_ARRAY_ELEMENT                                ~12     !1, 'type6'
  35    12        RAISE_ABSTRACT_ERROR                             ~14     '%00%7Bclosure%7D%2Fin%2FCrEev0x7f1e2207380c'
        13        ADD_ARRAY_ELEMENT                                ~12     ~14, 'type7'
  36    14        ADD_ARRAY_ELEMENT                                ~12     'MyClass%3A%3AmyCallbackMethod', 'type4'
  31    15        ADD_ARRAY_ELEMENT                                ~12     <array>, 'type5'
        16        QM_ASSIGN                                                !2
  40    17      > FE_RESET_R                                       $16     !2, ->40
        18    > > FE_FETCH_R                                       ~17     $16, !3, ->40
        19    >   QM_ASSIGN                                                !4
  41    20        ASSIGN_OBJ                                               '%0A'
        21        ASSIGN_OBJ                                               'Testing+'
        22        ASSIGN_OBJ                                               !4
        23        ASSIGN_OBJ                                               '%0A'
  42    24        INIT_FCALL                                               'var_dump'
        25        INIT_FCALL                                               'is_callable'
        26        DO_ICALL                                         $19     
        27        SEND_VAR                                                 $19
        28        DO_ICALL                                                 
  43    29        INIT_USER_CALL                                0          'call_user_func', !3
        30        DO_FCALL                                      0          
  45    31        INIT_DYNAMIC_CALL                                        !3
        32        DO_FCALL                                      0          
        33      > JMP                                                      ->39
  46    34  E > > CATCH                                       last         'Error'
  47    35    >   INIT_METHOD_CALL                                         !5, 'getMessage'
        36        DO_FCALL                                      0  $23     
        37        ASSIGN_OBJ                                               $23
        38        ASSIGN_OBJ                                               '%0A'
  40    39    > > JMP                                                      ->18
        40    >   FE_FREE                                                  $16
  49    41      > RETURN                                                   1

Function my_callback_function:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CrEev
function name:  my_callback_function
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   5     0  E >   ASSIGN_OBJ                                               'hello+world%21'
         1        ASSIGN_OBJ                                               '%0A'
   6     2      > RETURN                                                   null

End of function my_callback_function

Function %00%7Bclosure%7D%2Fin%2FCrEev0x7f1e2207380c:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CrEev
function name:  {closure}
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  35     0  E >   ASSIGN_OBJ                                               'Hello+Closure'
         1        ASSIGN_OBJ                                               '%0A'
         2      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FCrEev0x7f1e2207380c

Class ParentClass:
Function mycallbackmethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CrEev
function name:  myCallbackMethod
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  11     0  E >   ASSIGN_OBJ                                               'Hello+Parent%21'
         1        ASSIGN_OBJ                                               '%0A'
  12     2      > RETURN                                                   null

End of function mycallbackmethod

End of class ParentClass.

Class MyClass:
Function mycallbackmethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CrEev
function name:  myCallbackMethod
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  17     0  E >   ASSIGN_OBJ                                               'Hello+Child%21'
         1        ASSIGN_OBJ                                               '%0A'
  18     2      > RETURN                                                   null

End of function mycallbackmethod

End of class MyClass.

Class Invokable:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CrEev
function name:  __invoke
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  23     0  E >   ASSIGN_OBJ                                               'Hello+Invokable'
         1        ASSIGN_OBJ                                               '%0A'
  24     2      > RETURN                                                   null

End of function __invoke

End of class Invokable.

Generated using Vulcan Logic Dumper, using php 7.4.0