3v4l.org

run code in 300+ 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:  13
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        INIT_FCALL                                               'preg_replace'
          4        SEND_VAL                                                 '%7B%5E%28fopen%7Cmkdir%29%5C%28.%2A%3F%5C%29%3A+%7D'
          5        SEND_VAL                                                 ''
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                                 
    7    10      > RETURN                                                   <true>
    8    11*       VERIFY_RETURN_TYPE                                       
         12*     > 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:  13
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        INIT_FCALL                                               'preg_replace'
          4        SEND_VAL                                                 '%7B%5E%28fopen%7Cmkdir%29%5C%28.%2A%3F%5C%29%3A+%7D'
          5        SEND_VAL                                                 ''
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                                 
   32    10      > RETURN                                                   <true>
   33    11*       VERIFY_RETURN_TYPE                                       
         12*     > 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 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LsBph
function name:  stream_open
number of ops:  25
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        INIT_FCALL                                               'str_replace'
          5        SEND_VAL                                                 'logs%3A%2F%2F'
          6        SEND_VAL                                                 '%2Ftmp%2F'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !0, $5
   59    10        BEGIN_SILENCE                                    ~7      
         11        INIT_FCALL                                               'fopen'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $8      
         15        END_SILENCE                                              ~7
         16        ASSIGN                                                   !4, $8
   61    17        TYPE_CHECK                                    4          !4
         18      > JMPZ                                                     ~10, ->20
   62    19    > > RETURN                                                   <false>
   65    20    >   ASSIGN_OBJ                                               'handle'
         21        OP_DATA                                                  !4
   67    22      > RETURN                                                   <true>
   68    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null

End of function stream_open

End of class StreamHandler.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.56 ms | 1464 KiB | 23 Q