3v4l.org

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

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

End of function outer

Function %00%7Bclosure%7D%2Fin%2FRWUEE%3A8%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RWUEE
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
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
    9     3        ADD                                              ~3      !0, !1
          4        PRE_INC                                          ~4      !2
          5        ADD                                              ~5      ~3, ~4
          6      > RETURN                                                   ~5
   10     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRWUEE%3A8%240

Function %00%7Bclosure%7D%2Fin%2FRWUEE%3A11%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RWUEE
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
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   12     3        ADD                                              ~3      !0, !1
          4        PRE_INC                                          ~4      !2
          5        ADD                                              ~5      ~3, ~4
          6      > RETURN                                                   ~5
   13     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRWUEE%3A11%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.1 ms | 1407 KiB | 17 Q