3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ResourceType { public function __destruct() { echo "Resource is released.\n"; } } function get_callback() { $some_resource = new ResourceType(); $fn = function() use ($some_resource) { // this line does nothing // it overwrites a local variable which is never read // next time the closure runs, it will start again as the captured value $some_resource = null; }; return $fn; } $fn = get_callback(); echo "Before callback\n"; $fn(); echo "After callback\n"; unset($some_resource); echo "After destroying outer var\n"; // the captured reference is still live here; only destroying the closure frees it unset($fn); echo "After destroying closure\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WrTb5
function name:  (null)
number of ops:  12
compiled vars:  !0 = $fn, !1 = $some_resource
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'get_callback'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   22     3        ECHO                                                     'Before+callback%0A'
   23     4        INIT_DYNAMIC_CALL                                        !0
          5        DO_FCALL                                      0          
   24     6        ECHO                                                     'After+callback%0A'
   25     7        UNSET_CV                                                 !1
   26     8        ECHO                                                     'After+destroying+outer+var%0A'
   28     9        UNSET_CV                                                 !0
   29    10        ECHO                                                     'After+destroying+closure%0A'
         11      > RETURN                                                   1

Function get_callback:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WrTb5
function name:  get_callback
number of ops:  8
compiled vars:  !0 = $some_resource, !1 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   NEW                                              $2      'ResourceType'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   12     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWrTb5%3A12%240'
          4        BIND_LEXICAL                                             ~5, !0
          5        ASSIGN                                                   !1, ~5
   18     6      > RETURN                                                   !1
   19     7*     > RETURN                                                   null

End of function get_callback

Function %00%7Bclosure%7D%2Fin%2FWrTb5%3A12%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WrTb5
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $some_resource
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   BIND_STATIC                                              !0
   16     1        ASSIGN                                                   !0, null
   17     2      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWrTb5%3A12%240

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

End of function __destruct

End of class ResourceType.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.97 ms | 1399 KiB | 14 Q