3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ShopProduct { public $discount = 0; public $title; public $producerMainName; public $producerFirstName; protected $price; function __construct($title, $firstName, $mainName, $price) { $this->title = $title; $this->producerFirstName = $firstName; $this->producerMainName = $mainName; $this->price = $price; } function getSummaryLine(){ $base = "{$this->title} ( {$this->producerMainName}, "; $base .= "{$this->producerFirstName} )"; return $base; } function getProducer() { return "{$this->producerFirstName} " . "{$this->producerMainName}"; } function setDiscount(){ $this->discount=$num; } public function getPrice() { # code... return ($this->price - $this->discount); } } class ShopProductWriter{ private $products = array(); public function addProduct( ShopProduct $shopProduct){ $this->product[] = $shopProduct; } public function write(){ $str = ""; foreach ($this->products as $shopProduct) { $str .= "{$shopProduct->title}: "; $str .= "{$shopProduct->getProducer()}"; $str .= "{$shopProduct->getPrice()}\n"; } print $str; } } class CDProduct extends ShopProduct { public $playLength; function __construct($title, $firstName, $mainName, $price, $playLength){ parent::__construct($title, $firstName, $mainName, $price); $this->playLength = $playLength; } function getPlayLength(){ return $this->playLength; } function getSummaryLine(){ $base = parent::getSummaryLine(); $base .= " :Legth of song {$this->playLength}"; return $base; } } class BookProduct extends shopProduct{ public $numPages; function __construct($title, $firstName, $mainName, $price, $numPages){ parent::__construct($title, $firstName, $mainName, $price); $this->playLength = $playLength; } function getSummaryLine(){ $base = parent::getSummaryLine(); $base .= ": Number of pages - {$this->numPages}"; } function getProducer() { return "{$this->producerFirstName} " . "{$this->producerMainName}"; } function getPrice(){ return $this->price; } } $product2 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53); $product3 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53); $product4 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53); $product5 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53); print ShopProductWriter::write();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  (null)
number of ops:  36
compiled vars:  !0 = $product2, !1 = $product3, !2 = $product4, !3 = $product5
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  105     0  E >   NEW                                              $4      'CDProduct'
          1        SEND_VAL_EX                                              'On+my+own'
          2        SEND_VAL_EX                                              'Ashes'
          3        SEND_VAL_EX                                              'Remain'
          4        SEND_VAL_EX                                              10.99
          5        SEND_VAL_EX                                              2.53
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $4
  106     8        NEW                                              $7      'CDProduct'
          9        SEND_VAL_EX                                              'On+my+own'
         10        SEND_VAL_EX                                              'Ashes'
         11        SEND_VAL_EX                                              'Remain'
         12        SEND_VAL_EX                                              10.99
         13        SEND_VAL_EX                                              2.53
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $7
  107    16        NEW                                              $10     'CDProduct'
         17        SEND_VAL_EX                                              'On+my+own'
         18        SEND_VAL_EX                                              'Ashes'
         19        SEND_VAL_EX                                              'Remain'
         20        SEND_VAL_EX                                              10.99
         21        SEND_VAL_EX                                              2.53
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !2, $10
  108    24        NEW                                              $13     'CDProduct'
         25        SEND_VAL_EX                                              'On+my+own'
         26        SEND_VAL_EX                                              'Ashes'
         27        SEND_VAL_EX                                              'Remain'
         28        SEND_VAL_EX                                              10.99
         29        SEND_VAL_EX                                              2.53
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !3, $13
  110    32        INIT_STATIC_METHOD_CALL                                  'ShopProductWriter', 'write'
         33        DO_FCALL                                      0  $16     
         34        ECHO                                                     $16
         35      > RETURN                                                   1

Class ShopProduct:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  __construct
number of ops:  13
compiled vars:  !0 = $title, !1 = $firstName, !2 = $mainName, !3 = $price
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   14     4        ASSIGN_OBJ                                               'title'
          5        OP_DATA                                                  !0
   15     6        ASSIGN_OBJ                                               'producerFirstName'
          7        OP_DATA                                                  !1
   16     8        ASSIGN_OBJ                                               'producerMainName'
          9        OP_DATA                                                  !2
   17    10        ASSIGN_OBJ                                               'price'
         11        OP_DATA                                                  !3
   18    12      > RETURN                                                   null

End of function __construct

Function getsummaryline:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  getSummaryLine
number of ops:  13
compiled vars:  !0 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                      ~1      'title'
          1        ROPE_INIT                                     4  ~4      ~1
          2        ROPE_ADD                                      1  ~4      ~4, '+%28+'
          3        FETCH_OBJ_R                                      ~2      'producerMainName'
          4        ROPE_ADD                                      2  ~4      ~4, ~2
          5        ROPE_END                                      3  ~3      ~4, '%2C+'
          6        ASSIGN                                                   !0, ~3
   22     7        FETCH_OBJ_R                                      ~7      'producerFirstName'
          8        NOP                                                      
          9        FAST_CONCAT                                      ~8      ~7, '+%29'
         10        ASSIGN_OP                                     8          !0, ~8
   23    11      > RETURN                                                   !0
   24    12*     > RETURN                                                   null

End of function getsummaryline

Function getproducer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  getProducer
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_OBJ_R                                      ~0      'producerFirstName'
          1        NOP                                                      
          2        FAST_CONCAT                                      ~1      ~0, '+'
          3        FETCH_OBJ_R                                      ~2      'producerMainName'
          4        CAST                                          6  ~3      ~2
          5        CONCAT                                           ~4      ~1, ~3
          6      > RETURN                                                   ~4
   29     7*     > RETURN                                                   null

End of function getproducer

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

End of function setdiscount

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

End of function getprice

End of class ShopProduct.

Class ShopProductWriter:
Function addproduct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  addProduct
number of ops:  5
compiled vars:  !0 = $shopProduct
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   46     1        FETCH_OBJ_W                                      $1      'product'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   47     4      > RETURN                                                   null

End of function addproduct

Function write:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/InQJ6
function name:  write
number of ops:  21
compiled vars:  !0 = $str, !1 = $shopProduct
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN                                                   !0, ''
   51     1        FETCH_OBJ_R                                      ~3      'products'
          2      > FE_RESET_R                                       $4      ~3, ->18
          3    > > FE_FETCH_R                                               $4, !1, ->18
   53     4    >   FETCH_OBJ_R                                      ~5      !1, 'title'
          5        NOP                                                      
          6        FAST_CONCAT                                      ~6      ~5, '%3A+'
          7        ASSIGN_OP                                     8          !0, ~6
   54     8        INIT_METHOD_CALL                                         !1, 'getProducer'
          9        DO_FCALL                                      0  $8      
         10        CAST                                          6  ~9      $8
         11        ASSIGN_OP                                     8          !0, ~9
   55    12        INIT_METHOD_CALL                                         !1, 'getPrice'
         13        DO_FCALL                                      0  $11     
         14        NOP                                                      
         15        FAST_CONCAT                                      ~12     $11, '%0A'
         16        ASSIGN_OP                                     8          !0, ~12
   51    17      > JMP                                                      ->3
         18    >   FE_FREE                                                  $4
   58    19        ECHO                                                     !0
   59    20      > RETURN                                                   null

End of function write

End of class ShopProductWriter.

Class CDProduct:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  __construct
number of ops:  14
compiled vars:  !0 = $title, !1 = $firstName, !2 = $mainName, !3 = $price, !4 = $playLength
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
   67     5        INIT_STATIC_METHOD_CALL                                  
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !3
         10        DO_FCALL                                      0          
   68    11        ASSIGN_OBJ                                               'playLength'
         12        OP_DATA                                                  !4
   69    13      > RETURN                                                   null

End of function __construct

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

End of function getplaylength

Function getsummaryline:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  getSummaryLine
number of ops:  9
compiled vars:  !0 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   INIT_STATIC_METHOD_CALL                                  'getSummaryLine'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   77     3        NOP                                                      
          4        FETCH_OBJ_R                                      ~3      'playLength'
          5        FAST_CONCAT                                      ~4      '+%3ALegth+of+song+', ~3
          6        ASSIGN_OP                                     8          !0, ~4
   78     7      > RETURN                                                   !0
   79     8*     > RETURN                                                   null

End of function getsummaryline

Function getproducer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  getProducer
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_OBJ_R                                      ~0      'producerFirstName'
          1        NOP                                                      
          2        FAST_CONCAT                                      ~1      ~0, '+'
          3        FETCH_OBJ_R                                      ~2      'producerMainName'
          4        CAST                                          6  ~3      ~2
          5        CONCAT                                           ~4      ~1, ~3
          6      > RETURN                                                   ~4
   29     7*     > RETURN                                                   null

End of function getproducer

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

End of function setdiscount

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

End of function getprice

End of class CDProduct.

Class BookProduct:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  __construct
number of ops:  14
compiled vars:  !0 = $title, !1 = $firstName, !2 = $mainName, !3 = $price, !4 = $numPages, !5 = $playLength
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
   88     5        INIT_STATIC_METHOD_CALL                                  
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !3
         10        DO_FCALL                                      0          
   89    11        ASSIGN_OBJ                                               'playLength'
         12        OP_DATA                                                  !5
   90    13      > RETURN                                                   null

End of function __construct

Function getsummaryline:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  getSummaryLine
number of ops:  8
compiled vars:  !0 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   INIT_STATIC_METHOD_CALL                                  'getSummaryLine'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   93     3        NOP                                                      
          4        FETCH_OBJ_R                                      ~3      'numPages'
          5        FAST_CONCAT                                      ~4      '%3A+Number+of+pages+-+', ~3
          6        ASSIGN_OP                                     8          !0, ~4
   94     7      > RETURN                                                   null

End of function getsummaryline

Function getproducer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/InQJ6
function name:  getProducer
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   FETCH_OBJ_R                                      ~0      'producerFirstName'
          1        NOP                                                      
          2        FAST_CONCAT                                      ~1      ~0, '+'
          3        FETCH_OBJ_R                                      ~2      'producerMainName'
          4        CAST                                          6  ~3      ~2
          5        CONCAT                                           ~4      ~1, ~3
          6      > RETURN                                                   ~4
   98     7*     > RETURN                                                   null

End of function getproducer

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

End of function getprice

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

End of function setdiscount

End of class BookProduct.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.5 ms | 1419 KiB | 13 Q