3v4l.org

run code in 300+ 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($callback)); call_user_func($callback); try { $callback(); } catch( Error $e ) { echo $e->getMessage(), PHP_EOL; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 41
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 41
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Found catch point at position: 35
Branch analysis from position: 35
2 jumps found. (Code = 107) Position 1 = 36, Position 2 = -2
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
filename:       /in/C28tc
function name:  (null)
number of ops:  43
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      'MyClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $6
   28     3        NEW                                              $9      'Invokable'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $9
   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        DECLARE_LAMBDA_FUNCTION                          ~14     [0]
         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'
   30    16        ASSIGN                                                   !2, ~12
   40    17      > FE_RESET_R                                       $16     !2, ->41
         18    > > FE_FETCH_R                                       ~17     $16, !3, ->41
         19    >   ASSIGN                                                   !4, ~17
   41    20        ECHO                                                     '%0A'
         21        ECHO                                                     'Testing+'
         22        ECHO                                                     !4
         23        ECHO                                                     '%0A'
   42    24        INIT_FCALL                                               'var_dump'
         25        INIT_FCALL                                               'is_callable'
         26        SEND_VAR                                                 !3
         27        DO_ICALL                                         $19     
         28        SEND_VAR                                                 $19
         29        DO_ICALL                                                 
   43    30        INIT_USER_CALL                                0          'call_user_func', !3
         31        DO_FCALL                                      0          
   45    32        INIT_DYNAMIC_CALL                                        !3
         33        DO_FCALL                                      0          
         34      > JMP                                                      ->40
   46    35  E > > CATCH                                       last         'Error'
   47    36    >   INIT_METHOD_CALL                                         !5, 'getMessage'
         37        DO_FCALL                                      0  $23     
         38        ECHO                                                     $23
         39        ECHO                                                     '%0A'
   40    40    > > JMP                                                      ->18
         41    >   FE_FREE                                                  $16
   49    42      > 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/C28tc
function name:  {closure}
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ECHO                                                     'Hello+Closure'
          1        ECHO                                                     '%0A'
          2      > RETURN                                                   null

End of Dynamic Function 0

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

End of function my_callback_function

Class ParentClass:
Function mycallbackmethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C28tc
function name:  myCallbackMethod
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ECHO                                                     'Hello+Parent%21'
          1        ECHO                                                     '%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/C28tc
function name:  myCallbackMethod
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ECHO                                                     'Hello+Child%21'
          1        ECHO                                                     '%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/C28tc
function name:  __invoke
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ECHO                                                     'Hello+Invokable'
          1        ECHO                                                     '%0A'
   24     2      > RETURN                                                   null

End of function __invoke

End of class Invokable.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
192.79 ms | 1469 KiB | 15 Q