3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { private function customErrorHandler(int $code, string $msg): bool { var_dump(preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg)); return true; } protected function write(): void { set_error_handler([$this, 'customErrorHandler']); try { $stream = fopen('logs://foo.log', 'a'); trigger_error('Test test'); } finally { restore_error_handler(); } } public function test() { $this->write(); } } class Bar { public function customErrorHandler(int $code, string $msg): bool { var_dump(preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg)); return true; } protected function write(): void { set_error_handler([$this, 'customErrorHandler']); try { $stream = fopen('logs://foo.log', 'a'); trigger_error('Test test'); } finally { restore_error_handler(); } } public function test() { $this->write(); } } class StreamHandler { public $context; protected $handle; public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool { $path = str_replace('logs://', '/tmp/', $path); $handle = @fopen($path, $mode); if ($handle === false) { return false; } $this->handle = $handle; return true; } } stream_wrapper_register('logs', StreamHandler::class); touch('/tmp/foo.log'); chmod('/tmp/foo.log', 0444); (new Bar)->test(); (new Foo)->test();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  (null)
number of ops:  20
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   70     0  E >   INIT_FCALL                                                   'stream_wrapper_register'
          1        SEND_VAL                                                     'logs'
          2        SEND_VAL                                                     'StreamHandler'
          3        DO_ICALL                                                     
   72     4        INIT_FCALL                                                   'touch'
          5        SEND_VAL                                                     '%2Ftmp%2Ffoo.log'
          6        DO_ICALL                                                     
   73     7        INIT_FCALL                                                   'chmod'
          8        SEND_VAL                                                     '%2Ftmp%2Ffoo.log'
          9        SEND_VAL                                                     292
         10        DO_ICALL                                                     
   74    11        NEW                                                  $3      'Bar'
         12        DO_FCALL                                          0          
         13        INIT_METHOD_CALL                                             $3, 'test'
         14        DO_FCALL                                          0          
   75    15        NEW                                                  $6      'Foo'
         16        DO_FCALL                                          0          
         17        INIT_METHOD_CALL                                             $6, 'test'
         18        DO_FCALL                                          0          
         19      > RETURN                                                       1

Class Foo:
Function customerrorhandler:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  customErrorHandler
number of ops:  10
compiled vars:  !0 = $code, !1 = $msg
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        INIT_FCALL                                                   'var_dump'
          3        FRAMELESS_ICALL_3                preg_replace        ~2      '%7B%5E%28fopen%7Cmkdir%29%5C%28.%2A%3F%5C%29%3A+%7D', ''
          4        OP_DATA                                                      !1
          5        SEND_VAL                                                     ~2
          6        DO_ICALL                                                     
    7     7      > RETURN                                                       <true>
    8     8*       VERIFY_RETURN_TYPE                                           
          9*     > RETURN                                                       null

End of function customerrorhandler

Function write:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 162) Position 1 = 16, Position 2 = 15
Branch analysis from position: 16
1 jumps found. (Code = 163) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  write
number of ops:  20
compiled vars:  !0 = $stream
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                                   'set_error_handler'
          1        FETCH_THIS                                           ~1      
          2        INIT_ARRAY                                           ~2      ~1
          3        ADD_ARRAY_ELEMENT                                    ~2      'customErrorHandler'
          4        SEND_VAL                                                     ~2
          5        DO_ICALL                                                     
   14     6        INIT_FCALL                                                   'fopen'
          7        SEND_VAL                                                     'logs%3A%2F%2Ffoo.log'
          8        SEND_VAL                                                     'a'
          9        DO_ICALL                                             $5      
         10        ASSIGN                                                       !0, $5
   15    11        INIT_FCALL                                                   'trigger_error'
         12        SEND_VAL                                                     'Test+test'
         13        DO_ICALL                                                     
   16    14      > FAST_CALL                                                    ->16
         15    > > JMP                                                          ->19
   17    16    >   INIT_FCALL                                                   'restore_error_handler'
         17        DO_ICALL                                                     
         18      > FAST_RET                                                     
   19    19    > > RETURN                                                       null

End of function write

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  test
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   INIT_METHOD_CALL                                             'write'
          1        DO_FCALL                                          0          
   24     2      > RETURN                                                       null

End of function test

End of class Foo.

Class Bar:
Function customerrorhandler:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  customErrorHandler
number of ops:  10
compiled vars:  !0 = $code, !1 = $msg
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   30     2        INIT_FCALL                                                   'var_dump'
          3        FRAMELESS_ICALL_3                preg_replace        ~2      '%7B%5E%28fopen%7Cmkdir%29%5C%28.%2A%3F%5C%29%3A+%7D', ''
          4        OP_DATA                                                      !1
          5        SEND_VAL                                                     ~2
          6        DO_ICALL                                                     
   32     7      > RETURN                                                       <true>
   33     8*       VERIFY_RETURN_TYPE                                           
          9*     > RETURN                                                       null

End of function customerrorhandler

Function write:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 162) Position 1 = 16, Position 2 = 15
Branch analysis from position: 16
1 jumps found. (Code = 163) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  write
number of ops:  20
compiled vars:  !0 = $stream
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                                   'set_error_handler'
          1        FETCH_THIS                                           ~1      
          2        INIT_ARRAY                                           ~2      ~1
          3        ADD_ARRAY_ELEMENT                                    ~2      'customErrorHandler'
          4        SEND_VAL                                                     ~2
          5        DO_ICALL                                                     
   39     6        INIT_FCALL                                                   'fopen'
          7        SEND_VAL                                                     'logs%3A%2F%2Ffoo.log'
          8        SEND_VAL                                                     'a'
          9        DO_ICALL                                             $5      
         10        ASSIGN                                                       !0, $5
   40    11        INIT_FCALL                                                   'trigger_error'
         12        SEND_VAL                                                     'Test+test'
         13        DO_ICALL                                                     
   41    14      > FAST_CALL                                                    ->16
         15    > > JMP                                                          ->19
   42    16    >   INIT_FCALL                                                   'restore_error_handler'
         17        DO_ICALL                                                     
         18      > FAST_RET                                                     
   44    19    > > RETURN                                                       null

End of function write

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  test
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   48     0  E >   INIT_METHOD_CALL                                             'write'
          1        DO_FCALL                                          0          
   49     2      > RETURN                                                       null

End of function test

End of class Bar.

Class StreamHandler:
Function stream_open:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  stream_open
number of ops:  22
compiled vars:  !0 = $path, !1 = $mode, !2 = $options, !3 = $opened_path, !4 = $handle
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   56     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
          3        RECV                                                 !3      
   58     4        FRAMELESS_ICALL_3                str_replace         ~5      'logs%3A%2F%2F', '%2Ftmp%2F'
          5        OP_DATA                                                      !0
          6        ASSIGN                                                       !0, ~5
   59     7        BEGIN_SILENCE                                        ~7      
          8        INIT_FCALL                                                   'fopen'
          9        SEND_VAR                                                     !0
         10        SEND_VAR                                                     !1
         11        DO_ICALL                                             $8      
         12        END_SILENCE                                                  ~7
         13        ASSIGN                                                       !4, $8
   61    14        TYPE_CHECK                                        4          !4
         15      > JMPZ                                                         ~10, ->17
   62    16    > > RETURN                                                       <false>
   65    17    >   ASSIGN_OBJ                                                   'handle'
         18        OP_DATA                                                      !4
   67    19      > RETURN                                                       <true>
   68    20*       VERIFY_RETURN_TYPE                                           
         21*     > RETURN                                                       null

End of function stream_open

End of class StreamHandler.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.85 ms | 1668 KiB | 21 Q