3v4l.org

run code in 300+ 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                                               'sprintf'
          3        SEND_VAL                                                 'temp_func_%25s'
          4        INIT_FCALL                                               'md5'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $6      
          7        SEND_VAR                                                 $6
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !2, $7
    8    10        INIT_FCALL                                               'sprintf'
         11        SEND_VAL                                                 '%3C%3Fphp+if+%28%21function_exists%28%27%25s%27%29%29+%7Bfunction+%25s%28%25s%29%7B%25s%7D%7D'
         12        SEND_VAR                                                 !2
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $9      
         17        ASSIGN                                                   !3, $9
    9    18        INIT_FCALL                                               'tempnam'
         19        SEND_VAL                                                 '%2Ftmp'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                         $11     
         22        ASSIGN                                                   !4, $11
   10    23        INIT_FCALL                                               'fopen'
         24        SEND_VAR                                                 !4
         25        SEND_VAL                                                 'w%2B'
         26        DO_ICALL                                         $13     
         27        ASSIGN                                                   !5, $13
   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                          ~19     [0]
         40        BIND_LEXICAL                                             ~19, !2
   17    41      > RETURN                                                   ~19
   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}
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                                               'sprintf'
          3        SEND_VAL                                                 'temp_func_%25s'
          4        INIT_FCALL                                               'md5'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !2, $5
   22    10        INIT_FCALL                                               'sprintf'
         11        SEND_VAL                                                 'if+%28%21function_exists%28%27%25s%27%29%29+%7Bfunction+%25s%28%25s%29%7B%25s%7D%7D'
         12        SEND_VAR                                                 !2
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $7      
         17        ASSIGN                                                   !3, $7
   23    18        INCLUDE_OR_EVAL                                          !3, EVAL
   24    19        DECLARE_LAMBDA_FUNCTION                          ~10     [0]
         20        BIND_LEXICAL                                             ~10, !2
   26    21      > RETURN                                                   ~10
   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}
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.0.0


preferences:
145.44 ms | 1018 KiB | 22 Q