3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* * Example: Does the use keyword in PHP closures pass by reference? * * https://stackoverflow.com/a/10869632/367456 */ function bar(&$var) { $foo = function() use ($var) { debug_zval_dump($var); $var++; }; $foo(); }; $my_var = 0; bar($my_var); echo $my_var;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CMSHY
function name:  (null)
number of ops:  6
compiled vars:  !0 = $my_var
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                       !0, 0
   19     1        INIT_FCALL                                                   'bar'
          2        SEND_REF                                                     !0
          3        DO_FCALL                                          0          
   20     4        ECHO                                                         !0
   21     5      > RETURN                                                       1

Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CMSHY
function name:  bar
number of ops:  7
compiled vars:  !0 = $var, !1 = $foo
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
   10     1        DECLARE_LAMBDA_FUNCTION                              ~2      [0]
          2        BIND_LEXICAL                                                 ~2, !0
          3        ASSIGN                                                       !1, ~2
   15     4        INIT_DYNAMIC_CALL                                            !1
          5        DO_FCALL                                          0          
   16     6      > 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/CMSHY
function name:  {closure:bar():10}
number of ops:  6
compiled vars:  !0 = $var
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   BIND_STATIC                                                  !0
   12     1        INIT_FCALL                                                   'debug_zval_dump'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                                     
   13     4        PRE_INC                                                      !0
   14     5      > RETURN                                                       null

End of Dynamic Function 0

End of function bar

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.66 ms | 3304 KiB | 15 Q