3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Product { public $price; public function __construct($price) { $this->price = $price; } } class Calculator { public $modifiers = []; public function __construct(array $modifiers) { $this->modifiers = $modifiers; } public function calculate($value) { foreach ($this->modifiers as $modifier) { $value = $modifier->modify($value); } return $value; } } interface Modifier { function modify($value); } class TaxModifier { public $percent; public function modify($value) { return $value * ($this->percent + 1); } public function __construct($percent) { $this->percent = $percent; } } class DiscountModifier { public $discount; public function modify($value) { return $value - $this->discount; } public function __construct($discount) { $this->discount = $discount; } } $product = new Product(19.95); $calculator = new Calculator([ new TaxModifier(0.07), new TaxModifier(0.08), new DiscountModifier(8.00), ]); echo $calculator->calculate($product->price);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHDJ3
function name:  (null)
number of ops:  27
compiled vars:  !0 = $product, !1 = $calculator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   NEW                                              $2      'Product'
          1        SEND_VAL_EX                                              19.95
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   69     4        NEW                                              $5      'Calculator'
   70     5        NEW                                              $6      'TaxModifier'
          6        SEND_VAL_EX                                              0.07
          7        DO_FCALL                                      0          
          8        INIT_ARRAY                                       ~8      $6
   71     9        NEW                                              $9      'TaxModifier'
         10        SEND_VAL_EX                                              0.08
         11        DO_FCALL                                      0          
         12        ADD_ARRAY_ELEMENT                                ~8      $9
   72    13        NEW                                              $11     'DiscountModifier'
         14        SEND_VAL_EX                                              8
         15        DO_FCALL                                      0          
         16        ADD_ARRAY_ELEMENT                                ~8      $11
         17        SEND_VAL_EX                                              ~8
         18        DO_FCALL                                      0          
   69    19        ASSIGN                                                   !1, $5
   75    20        INIT_METHOD_CALL                                         !1, 'calculate'
         21        CHECK_FUNC_ARG                                           
         22        FETCH_OBJ_FUNC_ARG                               $15     !0, 'price'
         23        SEND_FUNC_ARG                                            $15
         24        DO_FCALL                                      0  $16     
         25        ECHO                                                     $16
         26      > RETURN                                                   1

Class Product:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHDJ3
function name:  __construct
number of ops:  4
compiled vars:  !0 = $price
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        ASSIGN_OBJ                                               'price'
          2        OP_DATA                                                  !0
   10     3      > RETURN                                                   null

End of function __construct

End of class Product.

Class Calculator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHDJ3
function name:  __construct
number of ops:  4
compiled vars:  !0 = $modifiers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        ASSIGN_OBJ                                               'modifiers'
          2        OP_DATA                                                  !0
   20     3      > RETURN                                                   null

End of function __construct

Function calculate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/NHDJ3
function name:  calculate
number of ops:  12
compiled vars:  !0 = $value, !1 = $modifier
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        FETCH_OBJ_R                                      ~2      'modifiers'
          2      > FE_RESET_R                                       $3      ~2, ->9
          3    > > FE_FETCH_R                                               $3, !1, ->9
   26     4    >   INIT_METHOD_CALL                                         !1, 'modify'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !0, $4
   24     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $3
   28    10      > RETURN                                                   !0
   29    11*     > RETURN                                                   null

End of function calculate

End of class Calculator.

Class Modifier:
Function modify:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHDJ3
function name:  modify
number of ops:  2
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function modify

End of class Modifier.

Class TaxModifier:
Function modify:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHDJ3
function name:  modify
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        FETCH_OBJ_R                                      ~1      'percent'
          2        ADD                                              ~2      ~1, 1
          3        MUL                                              ~3      !0, ~2
          4      > RETURN                                                   ~3
   44     5*     > RETURN                                                   null

End of function modify

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHDJ3
function name:  __construct
number of ops:  4
compiled vars:  !0 = $percent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        ASSIGN_OBJ                                               'percent'
          2        OP_DATA                                                  !0
   49     3      > RETURN                                                   null

End of function __construct

End of class TaxModifier.

Class DiscountModifier:
Function modify:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHDJ3
function name:  modify
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   58     1        FETCH_OBJ_R                                      ~1      'discount'
          2        SUB                                              ~2      !0, ~1
          3      > RETURN                                                   ~2
   59     4*     > RETURN                                                   null

End of function modify

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHDJ3
function name:  __construct
number of ops:  4
compiled vars:  !0 = $discount
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
   63     1        ASSIGN_OBJ                                               'discount'
          2        OP_DATA                                                  !0
   64     3      > RETURN                                                   null

End of function __construct

End of class DiscountModifier.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.74 ms | 1394 KiB | 13 Q