3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Lock { function __destruct() { echo "***lock released now***\n"; } } class DummyFileHandler { function lock(string $lock_type): Lock { return new Lock; } function readAll() { throw new DummyFileHandlerException('Uh oh!'); } } class DummyFileHandlerException extends Exception { }; function process_file(string $path): string { try { $file = new DummyFileHandler($path); $lock = $file->lock('shared'); $content = (function (Lock $lock) use ($file) { return $file->readAll(); })($lock); } catch (DummyFileHandlerException $e) { // release $file and $lock echo "unsetting \$lock...\n"; unset($file, $lock); // but $lock is in fact not yet released, it can be retrieved through the stack trace echo "lock: "; var_dump($e->getTrace()[1]['args'][0]); throw new Exception('Processing failed', previous: $e); } return $content; } process_file('/some/file.txt');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KJaL1
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   INIT_FCALL                                               'process_file'
          1        SEND_VAL                                                 '%2Fsome%2Ffile.txt'
          2        DO_FCALL                                      0          
          3      > RETURN                                                   1

Function process_file:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 16
Branch analysis from position: 16
2 jumps found. (Code = 107) Position 1 = 17, Position 2 = -2
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/KJaL1
function name:  process_file
number of ops:  39
compiled vars:  !0 = $path, !1 = $file, !2 = $lock, !3 = $content, !4 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        NEW                                              $5      'DummyFileHandler'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $5
   24     5        INIT_METHOD_CALL                                         !1, 'lock'
          6        SEND_VAL_EX                                              'shared'
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !2, $8
   25     9        DECLARE_LAMBDA_FUNCTION                          ~10     [0]
         10        BIND_LEXICAL                                             ~10, !1
   27    11        INIT_DYNAMIC_CALL                                        ~10
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0  $11     
   25    14        ASSIGN                                                   !3, $11
         15      > JMP                                                      ->35
   28    16  E > > CATCH                                       last         'DummyFileHandlerException'
   30    17    >   ECHO                                                     'unsetting+%24lock...%0A'
   31    18        UNSET_CV                                                 !1
         19        UNSET_CV                                                 !2
   34    20        ECHO                                                     'lock%3A+'
   35    21        INIT_FCALL                                               'var_dump'
         22        INIT_METHOD_CALL                                         !4, 'getTrace'
         23        DO_FCALL                                      0  $13     
         24        FETCH_DIM_R                                      ~14     $13, 1
         25        FETCH_DIM_R                                      ~15     ~14, 'args'
         26        FETCH_DIM_R                                      ~16     ~15, 0
         27        SEND_VAL                                                 ~16
         28        DO_ICALL                                                 
   38    29        NEW                                              $18     'Exception'
         30        SEND_VAL_EX                                              'Processing+failed'
         31        SEND_VAR_EX                                              !4, 'previous'
         32        CHECK_UNDEF_ARGS                                         
         33        DO_FCALL                                      1          
         34      > THROW                                         0          $18
   41    35    >   VERIFY_RETURN_TYPE                                       !3
         36      > RETURN                                                   !3
   42    37*       VERIFY_RETURN_TYPE                                       
         38*     > 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/KJaL1
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $lock, !1 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   26     2        INIT_METHOD_CALL                                         !1, 'readAll'
          3        DO_FCALL                                      0  $2      
          4      > RETURN                                                   $2
   27     5*     > RETURN                                                   null

End of Dynamic Function 0

End of function process_file

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

End of function __destruct

End of class Lock.

Class DummyFileHandler:
Function lock:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KJaL1
function name:  lock
number of ops:  7
compiled vars:  !0 = $lock_type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        NEW                                              $1      'Lock'
          2        DO_FCALL                                      0          
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   13     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function lock

Function readall:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/KJaL1
function name:  readAll
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $0      'DummyFileHandlerException'
          1        SEND_VAL_EX                                              'Uh+oh%21'
          2        DO_FCALL                                      0          
          3      > THROW                                         0          $0
   16     4*     > RETURN                                                   null

End of function readall

End of class DummyFileHandler.

Class DummyFileHandlerException: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.38 ms | 1011 KiB | 15 Q