3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyClass { function doSomething() { echo "HELLO WORLD\n"; } } $myInstance = null; $broken = function() use ($myInstance) { if(!empty($myInstance)) $myInstance->doSomething(); else echo "\$myInstance is empty.\n"; var_dump($myInstance); // NULL }; $working = function() use (&$myInstance) { if(!empty($myInstance)) $myInstance->doSomething(); else print "\$myInstance is empty.\n"; }; $myInstance = new MyClass(); $myInstance->doSomething(); // Outputs HELLO WORLD. $broken(); // Outputs $myInstance is empty. NULL $working(); // Outputs HELLO WORLD.
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OYrM9
function name:  (null)
number of ops:  17
compiled vars:  !0 = $myInstance, !1 = $broken, !2 = $working
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ASSIGN                                                   !0, null
   11     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOYrM9%3A11%240'
          2        BIND_LEXICAL                                             ~4, !0
          3        ASSIGN                                                   !1, ~4
   17     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOYrM9%3A17%241'
          5        BIND_LEXICAL                                             ~6, !0
          6        ASSIGN                                                   !2, ~6
   22     7        NEW                                              $8      'MyClass'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $8
   24    10        INIT_METHOD_CALL                                         !0, 'doSomething'
         11        DO_FCALL                                      0          
   25    12        INIT_DYNAMIC_CALL                                        !1
         13        DO_FCALL                                      0          
   26    14        INIT_DYNAMIC_CALL                                        !2
         15        DO_FCALL                                      0          
         16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FOYrM9%3A11%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OYrM9
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $myInstance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   BIND_STATIC                                              !0
   12     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->7
          4    >   INIT_METHOD_CALL                                         !0, 'doSomething'
          5        DO_FCALL                                      0          
          6      > JMP                                                      ->8
   13     7    >   ECHO                                                     '%24myInstance+is+empty.%0A'
   14     8    >   INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
   15    11      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FOYrM9%3A11%240

Function %00%7Bclosure%7D%2Fin%2FOYrM9%3A17%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OYrM9
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $myInstance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   BIND_STATIC                                              !0
   18     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->7
          4    >   INIT_METHOD_CALL                                         !0, 'doSomething'
          5        DO_FCALL                                      0          
          6      > JMP                                                      ->8
   19     7    >   ECHO                                                     '%24myInstance+is+empty.%0A'
   20     8    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FOYrM9%3A17%241

Class MyClass:
Function dosomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OYrM9
function name:  doSomething
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ECHO                                                     'HELLO+WORLD%0A'
          1      > RETURN                                                   null

End of function dosomething

End of class MyClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.11 ms | 1400 KiB | 15 Q