3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sum = null; // global variable $sum2 = null; // global variable function outer() { global $sum; global $sum2; $hundred_more = 100; $sum = function ($a, $b) use (&$hundred_more) { return $a + $b + (++$hundred_more); }; $sum2 = function ($a, $b) use (&$hundred_more) { return $a + $b + (++$hundred_more); }; var_dump($hundred_more); } outer(); // define sum at the global scope and print 100 var_dump($sum(5, 10)); // 116 var_dump($sum(5, 10)); // 116 var_dump($sum2(5, 10)); // 116 var_dump($sum2(5, 10)); // 116 outer(); // redefine sum at the global scope and print 100 var_dump($sum(5, 10)); // 116 var_dump($sum(5, 10)); // 116 var_dump($sum2(5, 10)); // 116 var_dump($sum2(5, 10)); // 116
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vtVMM
function name:  (null)
number of ops:  63
compiled vars:  !0 = $sum, !1 = $sum2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, null
    4     1        ASSIGN                                                   !1, null
   18     2        INIT_FCALL                                               'outer'
          3        DO_FCALL                                      0          
   19     4        INIT_FCALL                                               'var_dump'
          5        INIT_DYNAMIC_CALL                                        !0
          6        SEND_VAL_EX                                              5
          7        SEND_VAL_EX                                              10
          8        DO_FCALL                                      0  $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                                 
   20    11        INIT_FCALL                                               'var_dump'
         12        INIT_DYNAMIC_CALL                                        !0
         13        SEND_VAL_EX                                              5
         14        SEND_VAL_EX                                              10
         15        DO_FCALL                                      0  $7      
         16        SEND_VAR                                                 $7
         17        DO_ICALL                                                 
   21    18        INIT_FCALL                                               'var_dump'
         19        INIT_DYNAMIC_CALL                                        !1
         20        SEND_VAL_EX                                              5
         21        SEND_VAL_EX                                              10
         22        DO_FCALL                                      0  $9      
         23        SEND_VAR                                                 $9
         24        DO_ICALL                                                 
   22    25        INIT_FCALL                                               'var_dump'
         26        INIT_DYNAMIC_CALL                                        !1
         27        SEND_VAL_EX                                              5
         28        SEND_VAL_EX                                              10
         29        DO_FCALL                                      0  $11     
         30        SEND_VAR                                                 $11
         31        DO_ICALL                                                 
   23    32        INIT_FCALL                                               'outer'
         33        DO_FCALL                                      0          
   24    34        INIT_FCALL                                               'var_dump'
         35        INIT_DYNAMIC_CALL                                        !0
         36        SEND_VAL_EX                                              5
         37        SEND_VAL_EX                                              10
         38        DO_FCALL                                      0  $14     
         39        SEND_VAR                                                 $14
         40        DO_ICALL                                                 
   25    41        INIT_FCALL                                               'var_dump'
         42        INIT_DYNAMIC_CALL                                        !0
         43        SEND_VAL_EX                                              5
         44        SEND_VAL_EX                                              10
         45        DO_FCALL                                      0  $16     
         46        SEND_VAR                                                 $16
         47        DO_ICALL                                                 
   26    48        INIT_FCALL                                               'var_dump'
         49        INIT_DYNAMIC_CALL                                        !1
         50        SEND_VAL_EX                                              5
         51        SEND_VAL_EX                                              10
         52        DO_FCALL                                      0  $18     
         53        SEND_VAR                                                 $18
         54        DO_ICALL                                                 
   27    55        INIT_FCALL                                               'var_dump'
         56        INIT_DYNAMIC_CALL                                        !1
         57        SEND_VAL_EX                                              5
         58        SEND_VAL_EX                                              10
         59        DO_FCALL                                      0  $20     
         60        SEND_VAR                                                 $20
         61        DO_ICALL                                                 
         62      > RETURN                                                   1

Function outer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vtVMM
function name:  outer
number of ops:  13
compiled vars:  !0 = $sum, !1 = $sum2, !2 = $hundred_more
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   BIND_GLOBAL                                              !0, 'sum'
    8     1        BIND_GLOBAL                                              !1, 'sum2'
    9     2        ASSIGN                                                   !2, 100
   10     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FvtVMM%3A10%240'
          4        BIND_LEXICAL                                             ~4, !2
          5        ASSIGN                                                   !0, ~4
   13     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FvtVMM%3A13%241'
          7        BIND_LEXICAL                                             ~6, !2
          8        ASSIGN                                                   !1, ~6
   16     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                                 
   17    12      > RETURN                                                   null

End of function outer

Function %00%7Bclosure%7D%2Fin%2FvtVMM%3A10%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vtVMM
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $a, !1 = $b, !2 = $hundred_more
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   11     3        ADD                                              ~3      !0, !1
          4        PRE_INC                                          ~4      !2
          5        ADD                                              ~5      ~3, ~4
          6      > RETURN                                                   ~5
   12     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FvtVMM%3A10%240

Function %00%7Bclosure%7D%2Fin%2FvtVMM%3A13%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vtVMM
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $a, !1 = $b, !2 = $hundred_more
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   14     3        ADD                                              ~3      !0, !1
          4        PRE_INC                                          ~4      !2
          5        ADD                                              ~5      ~3, ~4
          6      > RETURN                                                   ~5
   15     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FvtVMM%3A13%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.61 ms | 1407 KiB | 17 Q