3v4l.org

run code in 500+ PHP versions simultaneously
<?php $args = '$user, $number'; $body = 'echo "#$number: Hello $user.\n";'; function _create_function_without_eval($args, $body) { $func_name = sprintf('temp_func_%s', md5($body)); $code = sprintf("<?php if (!function_exists('%s')) {function %s(%s){%s}}", $func_name, $func_name, $args, $body); $func_file = tempnam('/tmp', $func_name); $handle = fopen($func_file, "w+"); fwrite($handle, $code); fclose($handle); include $func_file; unlink($func_file); return function(...$user_args) use ($func_name) { return call_user_func_array($func_name, $user_args); }; } function _create_function_with_eval($args, $body) { $func_name = sprintf('temp_func_%s', md5($body)); $code = sprintf("if (!function_exists('%s')) {function %s(%s){%s}}", $func_name, $func_name, $args, $body); eval($code); return function(...$user_args) use ($func_name) { return call_user_func_array($func_name, $user_args); }; } $fn_deprecated = create_function($args, $body); $fn_with_eval = _create_function_with_eval($args, $body); $fn_without_eval = _create_function_without_eval($args, $body); echo $fn_deprecated('Old Bob', '1'); echo $fn_without_eval('Bob without eval', 2); echo $fn_with_eval('Bob with eval', 3);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/urQ4k
function name:  (null)
number of ops:  33
compiled vars:  !0 = $args, !1 = $body, !2 = $fn_deprecated, !3 = $fn_with_eval, !4 = $fn_without_eval
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%24user%2C+%24number'
    4     1        ASSIGN                                                       !1, 'echo+%22%23%24number%3A+Hello+%24user.%5Cn%22%3B'
   29     2        INIT_FCALL_BY_NAME                                           'create_function'
          3        SEND_VAR_EX                                                  !0
          4        SEND_VAR_EX                                                  !1
          5        DO_FCALL                                          0  $7      
          6        ASSIGN                                                       !2, $7
   30     7        INIT_FCALL                                                   '_create_function_with_eval'
          8        SEND_VAR                                                     !0
          9        SEND_VAR                                                     !1
         10        DO_FCALL                                          0  $9      
         11        ASSIGN                                                       !3, $9
   31    12        INIT_FCALL                                                   '_create_function_without_eval'
         13        SEND_VAR                                                     !0
         14        SEND_VAR                                                     !1
         15        DO_FCALL                                          0  $11     
         16        ASSIGN                                                       !4, $11
   33    17        INIT_DYNAMIC_CALL                                            !2
         18        SEND_VAL_EX                                                  'Old+Bob'
         19        SEND_VAL_EX                                                  '1'
         20        DO_FCALL                                          0  $13     
         21        ECHO                                                         $13
   34    22        INIT_DYNAMIC_CALL                                            !4
         23        SEND_VAL_EX                                                  'Bob+without+eval'
         24        SEND_VAL_EX                                                  2
         25        DO_FCALL                                          0  $14     
         26        ECHO                                                         $14
   35    27        INIT_DYNAMIC_CALL                                            !3
         28        SEND_VAL_EX                                                  'Bob+with+eval'
         29        SEND_VAL_EX                                                  3
         30        DO_FCALL                                          0  $15     
         31        ECHO                                                         $15
         32      > RETURN                                                       1

Function _create_function_without_eval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/urQ4k
function name:  _create_function_without_eval
number of ops:  43
compiled vars:  !0 = $args, !1 = $body, !2 = $func_name, !3 = $code, !4 = $func_file, !5 = $handle
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    7     2        INIT_FCALL                                                   'md5'
          3        SEND_VAR                                                     !1
          4        DO_ICALL                                             $6      
          5        NOP                                                          
          6        FAST_CONCAT                                          ~7      'temp_func_', $6
          7        ASSIGN                                                       !2, ~7
    8     8        ROPE_INIT                                         9  ~10     '%3C%3Fphp+if+%28%21function_exists%28%27'
          9        ROPE_ADD                                          1  ~10     ~10, !2
         10        ROPE_ADD                                          2  ~10     ~10, '%27%29%29+%7Bfunction+'
         11        ROPE_ADD                                          3  ~10     ~10, !2
         12        ROPE_ADD                                          4  ~10     ~10, '%28'
         13        ROPE_ADD                                          5  ~10     ~10, !0
         14        ROPE_ADD                                          6  ~10     ~10, '%29%7B'
         15        ROPE_ADD                                          7  ~10     ~10, !1
         16        ROPE_END                                          8  ~9      ~10, '%7D%7D'
         17        ASSIGN                                                       !3, ~9
    9    18        INIT_FCALL                                                   'tempnam'
         19        SEND_VAL                                                     '%2Ftmp'
         20        SEND_VAR                                                     !2
         21        DO_ICALL                                             $16     
         22        ASSIGN                                                       !4, $16
   10    23        INIT_FCALL                                                   'fopen'
         24        SEND_VAR                                                     !4
         25        SEND_VAL                                                     'w%2B'
         26        DO_ICALL                                             $18     
         27        ASSIGN                                                       !5, $18
   11    28        INIT_FCALL                                                   'fwrite'
         29        SEND_VAR                                                     !5
         30        SEND_VAR                                                     !3
         31        DO_ICALL                                                     
   12    32        INIT_FCALL                                                   'fclose'
         33        SEND_VAR                                                     !5
         34        DO_ICALL                                                     
   13    35        INCLUDE_OR_EVAL                                              !4, INCLUDE
   14    36        INIT_FCALL                                                   'unlink'
         37        SEND_VAR                                                     !4
         38        DO_ICALL                                                     
   15    39        DECLARE_LAMBDA_FUNCTION                              ~24     [0]
         40        BIND_LEXICAL                                                 ~24, !2
   17    41      > RETURN                                                       ~24
   18    42*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/urQ4k
function name:  {closure:_create_function_without_eval():15}
number of ops:  8
compiled vars:  !0 = $user_args, !1 = $func_name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV_VARIADIC                                        !0      
          1        BIND_STATIC                                                  !1
   16     2        INIT_USER_CALL                                    0          'call_user_func_array', !1
          3        SEND_ARRAY                                                   !0
          4        CHECK_UNDEF_ARGS                                             
          5        DO_FCALL                                          1  $2      
          6      > RETURN                                                       $2
   17     7*     > RETURN                                                       null

End of Dynamic Function 0

End of function _create_function_without_eval

Function _create_function_with_eval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/urQ4k
function name:  _create_function_with_eval
number of ops:  23
compiled vars:  !0 = $args, !1 = $body, !2 = $func_name, !3 = $code
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   21     2        INIT_FCALL                                                   'md5'
          3        SEND_VAR                                                     !1
          4        DO_ICALL                                             $4      
          5        NOP                                                          
          6        FAST_CONCAT                                          ~5      'temp_func_', $4
          7        ASSIGN                                                       !2, ~5
   22     8        ROPE_INIT                                         9  ~8      'if+%28%21function_exists%28%27'
          9        ROPE_ADD                                          1  ~8      ~8, !2
         10        ROPE_ADD                                          2  ~8      ~8, '%27%29%29+%7Bfunction+'
         11        ROPE_ADD                                          3  ~8      ~8, !2
         12        ROPE_ADD                                          4  ~8      ~8, '%28'
         13        ROPE_ADD                                          5  ~8      ~8, !0
         14        ROPE_ADD                                          6  ~8      ~8, '%29%7B'
         15        ROPE_ADD                                          7  ~8      ~8, !1
         16        ROPE_END                                          8  ~7      ~8, '%7D%7D'
         17        ASSIGN                                                       !3, ~7
   23    18        INCLUDE_OR_EVAL                                              !3, EVAL
   24    19        DECLARE_LAMBDA_FUNCTION                              ~15     [0]
         20        BIND_LEXICAL                                                 ~15, !2
   26    21      > RETURN                                                       ~15
   27    22*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/urQ4k
function name:  {closure:_create_function_with_eval():24}
number of ops:  8
compiled vars:  !0 = $user_args, !1 = $func_name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV_VARIADIC                                        !0      
          1        BIND_STATIC                                                  !1
   25     2        INIT_USER_CALL                                    0          'call_user_func_array', !1
          3        SEND_ARRAY                                                   !0
          4        CHECK_UNDEF_ARGS                                             
          5        DO_FCALL                                          1  $2      
          6      > RETURN                                                       $2
   26     7*     > RETURN                                                       null

End of Dynamic Function 0

End of function _create_function_with_eval

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.86 ms | 2646 KiB | 21 Q