PHP Object-oriented, PHP inheritance in the relevant operation of PHP is particularly important, this article will explain in detail its related content.
<!--? PHP class Shopproduct {private $title; Private $producerMainName; Private $producerFirstName; protected $price; Private $discount = 0; Public function __construct ($title, $firstName, $mainName, $price) {$this--->title = $title; $this->producerfirstname = $firstName; $this->producermainname = $mainName; $this->price = $price; } public Function Getproducerfirstname () {return $this->producerfirstname; } public Function Getproducermainname () {return $this->producermainname; The Public Function SetDiscount ($num) {$this->discount = $num; } public Function Getdiscount () {return $this->discount; } public Function GetTitle () {return $this->title; } public Function GetPrice () {return ($this->price-$this->discount); Public Function Getproducer () {return ' {$this->producerfirstname} '. "{$this->producermainname}"; Public Function Getsummaryline () {$base = "{$this->title} ({$this->producermainname},"; $base. = "{$this->producerfirstname)}"; return $base; }} class Cdproduct extends Shopproduct {private $playLength = 0; Public function __construct ($title, $firstName, $mainName, $price, $playLength) {parent::__construct ($title, $f Irstname, $mainName, $price); $this->playlength = $playLength; } public Function Getplaylength () {return $this->playlength; Public Function Getsummaryline () {$base = Parent::getsummaryline (); $base. = ": Playing time-{$this->playlength}"; return $base; }} class Bookproduct extends Shopproduct {private $numPages = 0; Public function __construct ($title, $firstName, $mainName, $price, $numPages) {parent::__construct ($title, $firstNam E, $mainName, $price); $this->number= $numPages; }
Public Function Getnumberofpages () { return $this->numpages; } Public Function Getsummaryline () { $base = Parent::getsummaryline (); $base. = ": Page count-{$this->numpages}"; return $base; } Public Function GetPrice () { return $this->price; } }? >
This article is a detailed description of PHP object-oriented, PHP inheritance related code knowledge, more relevant content please focus on PHP Chinese web.