3v4l.org

run code in 300+ PHP versions simultaneously
<?php function proc_diff($text1, $text2, $options='') { $descriptors = [ 0 => [ 'file', '/dev/null', 'r' ], 1 => [ 'pipe', 'w' ], 2 => [ 'pipe', 'w' ], 3 => [ 'pipe', 'r' ], 4 => [ 'pipe', 'r' ], ]; $command = sprintf('diff %s /proc/self/fd/3 /proc/self/fd/4', $options); if( ! $p = proc_open( $command, $descriptors, $pipes ) ) { throw new \Exception('proc_open failed.'); } fwrite($pipes[3], $text1); fwrite($pipes[4], $text2); fclose($pipes[3]); fclose($pipes[4]); $ret = []; $ret['stdout'] = stream_get_contents($pipes[1]); $ret['stderr'] = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $ret['code'] = proc_close($p); return $ret; } $in1 = "foo\nbar\n"; $in2 = "foo\nbar\nbaz\n"; var_dump(proc_diff($in1, $in2, '-u'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jMDAM
function name:  (null)
number of ops:  11
compiled vars:  !0 = $in1, !1 = $in2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, 'foo%0Abar%0A'
   37     1        ASSIGN                                                   !1, 'foo%0Abar%0Abaz%0A'
   39     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'proc_diff'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 '-u'
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function proc_diff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jMDAM
function name:  proc_diff
number of ops:  67
compiled vars:  !0 = $text1, !1 = $text2, !2 = $options, !3 = $descriptors, !4 = $command, !5 = $p, !6 = $pipes, !7 = $ret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      ''
    3     3        ASSIGN                                                   !3, <array>
   12     4        INIT_FCALL                                               'sprintf'
          5        SEND_VAL                                                 'diff+%25s+%2Fproc%2Fself%2Ffd%2F3+%2Fproc%2Fself%2Ffd%2F4'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !4, $9
   14     9        INIT_FCALL                                               'proc_open'
         10        SEND_VAR                                                 !4
         11        SEND_VAR                                                 !3
         12        SEND_REF                                                 !6
         13        DO_ICALL                                         $11     
         14        ASSIGN                                           ~12     !5, $11
         15        BOOL_NOT                                         ~13     ~12
         16      > JMPZ                                                     ~13, ->21
   15    17    >   NEW                                              $14     'Exception'
         18        SEND_VAL_EX                                              'proc_open+failed.'
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $14
   18    21    >   INIT_FCALL                                               'fwrite'
         22        FETCH_DIM_R                                      ~16     !6, 3
         23        SEND_VAL                                                 ~16
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                                 
   19    26        INIT_FCALL                                               'fwrite'
         27        FETCH_DIM_R                                      ~18     !6, 4
         28        SEND_VAL                                                 ~18
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                                 
   21    31        INIT_FCALL                                               'fclose'
         32        FETCH_DIM_R                                      ~20     !6, 3
         33        SEND_VAL                                                 ~20
         34        DO_ICALL                                                 
   22    35        INIT_FCALL                                               'fclose'
         36        FETCH_DIM_R                                      ~22     !6, 4
         37        SEND_VAL                                                 ~22
         38        DO_ICALL                                                 
   24    39        ASSIGN                                                   !7, <array>
   25    40        INIT_FCALL                                               'stream_get_contents'
         41        FETCH_DIM_R                                      ~26     !6, 1
         42        SEND_VAL                                                 ~26
         43        DO_ICALL                                         $27     
         44        ASSIGN_DIM                                               !7, 'stdout'
         45        OP_DATA                                                  $27
   26    46        INIT_FCALL                                               'stream_get_contents'
         47        FETCH_DIM_R                                      ~29     !6, 2
         48        SEND_VAL                                                 ~29
         49        DO_ICALL                                         $30     
         50        ASSIGN_DIM                                               !7, 'stderr'
         51        OP_DATA                                                  $30
   28    52        INIT_FCALL                                               'fclose'
         53        FETCH_DIM_R                                      ~31     !6, 1
         54        SEND_VAL                                                 ~31
         55        DO_ICALL                                                 
   29    56        INIT_FCALL                                               'fclose'
         57        FETCH_DIM_R                                      ~33     !6, 2
         58        SEND_VAL                                                 ~33
         59        DO_ICALL                                                 
   31    60        INIT_FCALL                                               'proc_close'
         61        SEND_VAR                                                 !5
         62        DO_ICALL                                         $36     
         63        ASSIGN_DIM                                               !7, 'code'
         64        OP_DATA                                                  $36
   33    65      > RETURN                                                   !7
   34    66*     > RETURN                                                   null

End of function proc_diff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.18 ms | 1403 KiB | 28 Q