3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Calculator { public function calc($v) { return $v + 1; } } class MyCalculator extends Calculator { public function calc($v1, $v2 = 0) { return parent::calc($v1) + $v2; } } function calcArray(array $values, Calculator $calculator) { foreach ($values as &$v) { $v = $calculator->calc($v, $v); // Second aregument is wrong !! } return $values; } $ar = [1,2,3]; var_dump(calcArray($ar, new Calculator)); // ignores the second argument var_dump(calcArray($ar, new MyCalculator)); // UNEXPECTED: the second argument will be used
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/U2lnf
function name:  (null)
number of ops:  20
compiled vars:  !0 = $ar
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                       !0, <array>
   23     1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'calcarray'
          3        SEND_VAR                                                     !0
          4        NEW                                                  $2      'Calculator'
          5        DO_FCALL                                          0          
          6        SEND_VAR                                                     $2
          7        DO_FCALL                                          0  $4      
          8        SEND_VAR                                                     $4
          9        DO_ICALL                                                     
   24    10        INIT_FCALL                                                   'var_dump'
         11        INIT_FCALL                                                   'calcarray'
         12        SEND_VAR                                                     !0
         13        NEW                                                  $6      'MyCalculator'
         14        DO_FCALL                                          0          
         15        SEND_VAR                                                     $6
         16        DO_FCALL                                          0  $8      
         17        SEND_VAR                                                     $8
         18        DO_ICALL                                                     
         19      > RETURN                                                       1

Function calcarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/U2lnf
function name:  calcArray
number of ops:  13
compiled vars:  !0 = $values, !1 = $calculator, !2 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   16     2      > FE_RESET_RW                                          $3      !0, ->10
          3    > > FE_FETCH_RW                                                  $3, !2, ->10
   17     4    >   INIT_METHOD_CALL                                             !1, 'calc'
          5        SEND_VAR_EX                                                  !2
          6        SEND_VAR_EX                                                  !2
          7        DO_FCALL                                          0  $4      
          8        ASSIGN                                                       !2, $4
   16     9      > JMP                                                          ->3
         10    >   FE_FREE                                                      $3
   19    11      > RETURN                                                       !0
   20    12*     > RETURN                                                       null

End of function calcarray

Class Calculator:
Function calc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/U2lnf
function name:  calc
number of ops:  4
compiled vars:  !0 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
    5     1        ADD                                                  ~1      !0, 1
          2      > RETURN                                                       ~1
    6     3*     > RETURN                                                       null

End of function calc

End of class Calculator.

Class MyCalculator:
Function calc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/U2lnf
function name:  calc
number of ops:  8
compiled vars:  !0 = $v1, !1 = $v2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      0
   11     2        INIT_STATIC_METHOD_CALL                                      'calc'
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0  $2      
          5        ADD                                                  ~3      $2, !1
          6      > RETURN                                                       ~3
   12     7*     > RETURN                                                       null

End of function calc

End of class MyCalculator.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.99 ms | 2669 KiB | 16 Q