3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Illustrating PHP Function parameters. */ class o { private $v = 0; public function inc() { $this->v++; } public function getV() { return $this->v; } } function testParams(o $obj) { for ($x=0; $x < 10; $x++) { $obj->inc(); } return $obj->getV(); } function testParams2($fp, $text) { $text = "1." . $text . PHP_EOL; fwrite($fp, $text); } // Pass Array by Reference function testParams3(Array &$globArray) { array_push($globArray, 'grape'); } // Globally scoped variables $globArray = ['apple', 'banana', 'peach']; $obj = new o(); $r = fopen("/tmp/resource.txt", "w+"); $text = "This is some text."; // $retVal = testParams($obj); echo $retVal . PHP_EOL; echo $obj->getV() . PHP_EOL; echo PHP_EOL; echo "text before testParams2: \n"; echo "\t$text" . PHP_EOL; testParams2($r, $text); rewind($r); $fileData = fgets($r, 4096); echo "File Data:\n"; echo "\t$fileData"; echo "text After testParams2::\n"; echo "\t$text" . PHP_EOL; echo PHP_EOL; echo "Array Before testParams3:\n"; var_dump($globArray); echo PHP_EOL; testParams3($globArray); echo "Array After testParams3:\n"; var_dump($globArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vJFhs
function name:  (null)
number of ops:  61
compiled vars:  !0 = $globArray, !1 = $obj, !2 = $r, !3 = $text, !4 = $retVal, !5 = $fileData
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   ASSIGN                                                   !0, <array>
   38     1        NEW                                              $7      'o'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   39     4        INIT_FCALL                                               'fopen'
          5        SEND_VAL                                                 '%2Ftmp%2Fresource.txt'
          6        SEND_VAL                                                 'w%2B'
          7        DO_ICALL                                         $10     
          8        ASSIGN                                                   !2, $10
   40     9        ASSIGN                                                   !3, 'This+is+some+text.'
   43    10        INIT_FCALL                                               'testparams'
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $13     
         13        ASSIGN                                                   !4, $13
   44    14        CONCAT                                           ~15     !4, '%0A'
         15        ECHO                                                     ~15
   45    16        INIT_METHOD_CALL                                         !1, 'getV'
         17        DO_FCALL                                      0  $16     
         18        CONCAT                                           ~17     $16, '%0A'
         19        ECHO                                                     ~17
   47    20        ECHO                                                     '%0A'
   48    21        ECHO                                                     'text+before+testParams2%3A+%0A'
   49    22        NOP                                                      
         23        FAST_CONCAT                                      ~18     '%09', !3
         24        CONCAT                                           ~19     ~18, '%0A'
         25        ECHO                                                     ~19
   50    26        INIT_FCALL                                               'testparams2'
         27        SEND_VAR                                                 !2
         28        SEND_VAR                                                 !3
         29        DO_FCALL                                      0          
   51    30        INIT_FCALL                                               'rewind'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                                 
   52    33        INIT_FCALL                                               'fgets'
         34        SEND_VAR                                                 !2
         35        SEND_VAL                                                 4096
         36        DO_ICALL                                         $22     
         37        ASSIGN                                                   !5, $22
   53    38        ECHO                                                     'File+Data%3A%0A'
   54    39        NOP                                                      
         40        FAST_CONCAT                                      ~24     '%09', !5
         41        ECHO                                                     ~24
   55    42        ECHO                                                     'text+After+testParams2%3A%3A%0A'
   56    43        NOP                                                      
         44        FAST_CONCAT                                      ~25     '%09', !3
         45        CONCAT                                           ~26     ~25, '%0A'
         46        ECHO                                                     ~26
   58    47        ECHO                                                     '%0A'
   59    48        ECHO                                                     'Array+Before+testParams3%3A%0A'
   60    49        INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !0
         51        DO_ICALL                                                 
   62    52        ECHO                                                     '%0A'
   63    53        INIT_FCALL                                               'testparams3'
         54        SEND_REF                                                 !0
         55        DO_FCALL                                      0          
   64    56        ECHO                                                     'Array+After+testParams3%3A%0A'
   65    57        INIT_FCALL                                               'var_dump'
         58        SEND_VAR                                                 !0
         59        DO_ICALL                                                 
         60      > RETURN                                                   1

Function testparams:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 3
Branch analysis from position: 8
Branch analysis from position: 3
filename:       /in/vJFhs
function name:  testParams
number of ops:  12
compiled vars:  !0 = $obj, !1 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->6
   21     3    >   INIT_METHOD_CALL                                         !0, 'inc'
          4        DO_FCALL                                      0          
   20     5        PRE_INC                                                  !1
          6    >   IS_SMALLER                                               !1, 10
          7      > JMPNZ                                                    ~5, ->3
   23     8    >   INIT_METHOD_CALL                                         !0, 'getV'
          9        DO_FCALL                                      0  $6      
         10      > RETURN                                                   $6
   24    11*     > RETURN                                                   null

End of function testparams

Function testparams2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vJFhs
function name:  testParams2
number of ops:  10
compiled vars:  !0 = $fp, !1 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        CONCAT                                           ~2      '1.', !1
          3        CONCAT                                           ~3      ~2, '%0A'
          4        ASSIGN                                                   !1, ~3
   28     5        INIT_FCALL                                               'fwrite'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   29     9      > RETURN                                                   null

End of function testparams2

Function testparams3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vJFhs
function name:  testParams3
number of ops:  6
compiled vars:  !0 = $globArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_FCALL                                               'array_push'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 'grape'
          4        DO_ICALL                                                 
   34     5      > RETURN                                                   null

End of function testparams3

Class o:
Function inc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vJFhs
function name:  inc
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   PRE_INC_OBJ                                              'v'
   12     1      > RETURN                                                   null

End of function inc

Function getv:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vJFhs
function name:  getV
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_R                                      ~0      'v'
          1      > RETURN                                                   ~0
   16     2*     > RETURN                                                   null

End of function getv

End of class o.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.43 ms | 1014 KiB | 22 Q