3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CallableStringifier { private static $callables = array(); public static function stringify($callable) { $id = count(self::$callables); self::$callables[$id] = $callable; if (is_array($callable)) { $func = new ReflectionMethod($callable[0], $callable[1]); } else if (is_string($callable) && false !== strpos($callable, '::')) { $func = new ReflectionMethod($callable); } else { $func = new ReflectionFunction($callable); } $params = array(); foreach ($func->getParameters() as $param) { $params[$param->getPosition()] = '$' . $param->getName(); } return __CLASS__ . '::call(' . $id . ', ' . implode(', ', $params) . ');'; } public static function call() { $args = func_get_args(); $id = array_shift($args); return call_user_func_array(self::$callables[$id], $args); } } var_dump(CallableStringifier::stringify(function($arg1) { return $arg1; })); $func = create_function('$arg1', CallableStringifier::stringify(function($arg1) { return $arg1; })); echo $func(1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VibC8
function name:  (null)
number of ops:  21
compiled vars:  !0 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_STATIC_METHOD_CALL                                  'CallableStringifier', 'stringify'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FVibC8%3A37%240'
          3        SEND_VAL                                                 ~1
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   39     7        INIT_FCALL_BY_NAME                                       'create_function'
          8        SEND_VAL_EX                                              '%24arg1'
          9        INIT_STATIC_METHOD_CALL                                  'CallableStringifier', 'stringify'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FVibC8%3A39%241'
         11        SEND_VAL                                                 ~4
         12        DO_FCALL                                      0  $5      
         13        SEND_VAR_NO_REF_EX                                       $5
         14        DO_FCALL                                      0  $6      
         15        ASSIGN                                                   !0, $6
   41    16        INIT_DYNAMIC_CALL                                        !0
         17        SEND_VAL_EX                                              1
         18        DO_FCALL                                      0  $8      
         19        ECHO                                                     $8
         20      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FVibC8%3A37%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VibC8
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $arg1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1      > RETURN                                                   !0
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FVibC8%3A37%240

Function %00%7Bclosure%7D%2Fin%2FVibC8%3A39%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VibC8
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $arg1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1      > RETURN                                                   !0
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FVibC8%3A39%241

Class CallableStringifier:
Function stringify:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 50
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 50
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 50
Branch analysis from position: 41
Branch analysis from position: 50
Branch analysis from position: 27
filename:       /in/VibC8
function name:  stringify
number of ops:  61
compiled vars:  !0 = $callable, !1 = $id, !2 = $func, !3 = $params, !4 = $param
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        FETCH_STATIC_PROP_R          unknown             ~5      'callables'
          2        COUNT                                            ~6      ~5
          3        ASSIGN                                                   !1, ~6
   10     4        FETCH_STATIC_PROP_W          unknown             $8      'callables'
          5        ASSIGN_DIM                                               $8, !1
          6        OP_DATA                                                  !0
   12     7        TYPE_CHECK                                  128          !0
          8      > JMPZ                                                     ~10, ->19
   13     9    >   NEW                                              $11     'ReflectionMethod'
         10        CHECK_FUNC_ARG                                           
         11        FETCH_DIM_FUNC_ARG                               $12     !0, 0
         12        SEND_FUNC_ARG                                            $12
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $13     !0, 1
         15        SEND_FUNC_ARG                                            $13
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !2, $11
         18      > JMP                                                      ->37
   14    19    >   TYPE_CHECK                                   64  ~16     !0
         20      > JMPZ_EX                                          ~16     ~16, ->27
         21    >   INIT_FCALL                                               'strpos'
         22        SEND_VAR                                                 !0
         23        SEND_VAL                                                 '%3A%3A'
         24        DO_ICALL                                         $17     
         25        TYPE_CHECK                                  1018  ~18     $17
         26        BOOL                                             ~16     ~18
         27    > > JMPZ                                                     ~16, ->33
   15    28    >   NEW                                              $19     'ReflectionMethod'
         29        SEND_VAR_EX                                              !0
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !2, $19
         32      > JMP                                                      ->37
   17    33    >   NEW                                              $22     'ReflectionFunction'
         34        SEND_VAR_EX                                              !0
         35        DO_FCALL                                      0          
         36        ASSIGN                                                   !2, $22
   20    37    >   ASSIGN                                                   !3, <array>
   21    38        INIT_METHOD_CALL                                         !2, 'getParameters'
         39        DO_FCALL                                      0  $26     
         40      > FE_RESET_R                                       $27     $26, ->50
         41    > > FE_FETCH_R                                               $27, !4, ->50
   22    42    >   INIT_METHOD_CALL                                         !4, 'getPosition'
         43        DO_FCALL                                      0  $28     
         44        INIT_METHOD_CALL                                         !4, 'getName'
         45        DO_FCALL                                      0  $30     
         46        CONCAT                                           ~31     '%24', $30
         47        ASSIGN_DIM                                               !3, $28
         48        OP_DATA                                                  ~31
   21    49      > JMP                                                      ->41
         50    >   FE_FREE                                                  $27
   25    51        CONCAT                                           ~32     'CallableStringifier%3A%3Acall%28', !1
         52        CONCAT                                           ~33     ~32, '%2C+'
         53        INIT_FCALL                                               'implode'
         54        SEND_VAL                                                 '%2C+'
         55        SEND_VAR                                                 !3
         56        DO_ICALL                                         $34     
         57        CONCAT                                           ~35     ~33, $34
         58        CONCAT                                           ~36     ~35, '%29%3B'
         59      > RETURN                                                   ~36
   26    60*     > RETURN                                                   null

End of function stringify

Function call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VibC8
function name:  call
number of ops:  14
compiled vars:  !0 = $args, !1 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FUNC_GET_ARGS                                    ~2      
          1        ASSIGN                                                   !0, ~2
   31     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   33     6        FETCH_STATIC_PROP_R          global lock         ~6      'callables'
          7        FETCH_DIM_R                                      ~7      ~6, !1
          8        INIT_USER_CALL                                0          'call_user_func_array', ~7
          9        SEND_ARRAY                                               !0
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      0  $8      
         12      > RETURN                                                   $8
   34    13*     > RETURN                                                   null

End of function call

End of class CallableStringifier.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.77 ms | 1396 KiB | 21 Q