3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Product { protected $price; protected $discount; public function getPrice() { return $this->price->getValue(); } public function setPrice($price, $type) { $this->price = new Price($price); $this->price->setType($type); } public function getDiscount() { return $this->discount->getValue(); } public function setDiscount($discount, $type) { $this->discount = new Discount($discount); $this->discount->setType($type); } } class Price { protected $type; // 0 - one-off price, 1 - monthly price, 2 - combination of previous two; protected $value; function __construct($value) { if (is_numeric($value)) { $this->value = round(floatval($value), 2); } else { $this->value = 0; } } public function getType() { return $this->type; } public function setType($type) { if (is_numeric($type) && in_array(intval($type), array(0, 1, 2))) { $this->type = intval($type); } else { $this->type = 0; } } public function getValue() { return $this->value; } } class Discount extends Price{} class Shopcart { protected $shopping_list; function __construct($products) { $this->shopping_list[] = $products; } public function getTotalPrice() { $cost = 0; foreach ($this->shopping_list as $item) { $cost += $item->getCost(); } return $cost; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SOpYf
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E > > RETURN                                                   1

Class Product:
Function getprice:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SOpYf
function name:  getPrice
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   FETCH_OBJ_R                                      ~0      'price'
          1        INIT_METHOD_CALL                                         ~0, 'getValue'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
    9     4*     > RETURN                                                   null

End of function getprice

Function setprice:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SOpYf
function name:  setPrice
number of ops:  12
compiled vars:  !0 = $price, !1 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        NEW                                              $3      'Price'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               'price'
          6        OP_DATA                                                  $3
   13     7        FETCH_OBJ_R                                      ~5      'price'
          8        INIT_METHOD_CALL                                         ~5, 'setType'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
   14    11      > RETURN                                                   null

End of function setprice

Function getdiscount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SOpYf
function name:  getDiscount
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_OBJ_R                                      ~0      'discount'
          1        INIT_METHOD_CALL                                         ~0, 'getValue'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   18     4*     > RETURN                                                   null

End of function getdiscount

Function setdiscount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SOpYf
function name:  setDiscount
number of ops:  12
compiled vars:  !0 = $discount, !1 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        NEW                                              $3      'Discount'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               'discount'
          6        OP_DATA                                                  $3
   22     7        FETCH_OBJ_R                                      ~5      'discount'
          8        INIT_METHOD_CALL                                         ~5, 'setType'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
   23    11      > RETURN                                                   null

End of function setdiscount

End of class Product.

Class Price:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SOpYf
function name:  __construct
number of ops:  16
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > JMPZ                                                     $1, ->13
   33     5    >   INIT_FCALL                                               'round'
          6        CAST                                          5  ~3      !0
          7        SEND_VAL                                                 ~3
          8        SEND_VAL                                                 2
          9        DO_ICALL                                         $4      
         10        ASSIGN_OBJ                                               'value'
         11        OP_DATA                                                  $4
         12      > JMP                                                      ->15
   35    13    >   ASSIGN_OBJ                                               'value'
         14        OP_DATA                                                  0
   37    15    > > RETURN                                                   null

End of function __construct

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

End of function gettype

Function settype:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/SOpYf
function name:  setType
number of ops:  19
compiled vars:  !0 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   44     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > JMPZ_EX                                          ~2      $1, ->11
          5    >   INIT_FCALL                                               'in_array'
          6        CAST                                          4  ~3      !0
          7        SEND_VAL                                                 ~3
          8        SEND_VAL                                                 <array>
          9        DO_ICALL                                         $4      
         10        BOOL                                             ~2      $4
         11    > > JMPZ                                                     ~2, ->16
   45    12    >   CAST                                          4  ~6      !0
         13        ASSIGN_OBJ                                               'type'
         14        OP_DATA                                                  ~6
         15      > JMP                                                      ->18
   47    16    >   ASSIGN_OBJ                                               'type'
         17        OP_DATA                                                  0
   49    18    > > RETURN                                                   null

End of function settype

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

End of function getvalue

End of class Price.

Class Discount:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SOpYf
function name:  __construct
number of ops:  16
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > JMPZ                                                     $1, ->13
   33     5    >   INIT_FCALL                                               'round'
          6        CAST                                          5  ~3      !0
          7        SEND_VAL                                                 ~3
          8        SEND_VAL                                                 2
          9        DO_ICALL                                         $4      
         10        ASSIGN_OBJ                                               'value'
         11        OP_DATA                                                  $4
         12      > JMP                                                      ->15
   35    13    >   ASSIGN_OBJ                                               'value'
         14        OP_DATA                                                  0
   37    15    > > RETURN                                                   null

End of function __construct

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

End of function gettype

Function settype:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/SOpYf
function name:  setType
number of ops:  19
compiled vars:  !0 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   44     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > JMPZ_EX                                          ~2      $1, ->11
          5    >   INIT_FCALL                                               'in_array'
          6        CAST                                          4  ~3      !0
          7        SEND_VAL                                                 ~3
          8        SEND_VAL                                                 <array>
          9        DO_ICALL                                         $4      
         10        BOOL                                             ~2      $4
         11    > > JMPZ                                                     ~2, ->16
   45    12    >   CAST                                          4  ~6      !0
         13        ASSIGN_OBJ                                               'type'
         14        OP_DATA                                                  ~6
         15      > JMP                                                      ->18
   47    16    >   ASSIGN_OBJ                                               'type'
         17        OP_DATA                                                  0
   49    18    > > RETURN                                                   null

End of function settype

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

End of function getvalue

End of class Discount.

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

End of function __construct

Function gettotalprice:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/SOpYf
function name:  getTotalPrice
number of ops:  11
compiled vars:  !0 = $cost, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   ASSIGN                                                   !0, 0
   68     1        FETCH_OBJ_R                                      ~3      'shopping_list'
          2      > FE_RESET_R                                       $4      ~3, ->8
          3    > > FE_FETCH_R                                               $4, !1, ->8
   69     4    >   INIT_METHOD_CALL                                         !1, 'getCost'
          5        DO_FCALL                                      0  $5      
          6        ASSIGN_OP                                     1          !0, $5
   68     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $4
   71     9      > RETURN                                                   !0
   72    10*     > RETURN                                                   null

End of function gettotalprice

End of class Shopcart.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.06 ms | 1412 KiB | 19 Q