3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = 10; function outer($x) { function inner($y) { global $x; // uses the actually global $x from line 2, not the param from line 3 return $x + $y; } return inner(5); } echo outer(5); // expected: 10, actual: 15 /* $z = 10; function outer2($z) { function inner($w) use ($z) { // syntax error, function (...) use (...) form is reserved for closures return $z + $w; } return inner(5); } echo outer2(5); // expected: 10, actual: syntax error */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aUPHU
function name:  (null)
number of ops:  6
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 10
   10     1        INIT_FCALL                                               'outer'
          2        SEND_VAL                                                 5
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
   21     5      > RETURN                                                   1

Function outer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aUPHU
function name:  outer
number of ops:  7
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        DECLARE_FUNCTION                                         'inner'
    8     2        INIT_FCALL_BY_NAME                                       'inner'
          3        SEND_VAL_EX                                              5
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
    9     6*     > RETURN                                                   null

End of function outer

Function %00inner%2Fin%2FaUPHU%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aUPHU
function name:  inner
number of ops:  5
compiled vars:  !0 = $y, !1 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        BIND_GLOBAL                                              !1, 'x'
    6     2        ADD                                              ~2      !1, !0
          3      > RETURN                                                   ~2
    7     4*     > RETURN                                                   null

End of function %00inner%2Fin%2FaUPHU%3A4%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.13 ms | 1402 KiB | 14 Q