Home>Article>Backend Development> Explain PHP object-oriented, PHP inheritance related code
PHP is object-oriented, and PHP inheritance is particularly important in PHP-related operations. This article will explain its related content in detail.
title = $title; $this->producerFirstName = $firstName; $this->producerMainName = $mainName; $this->price = $price; } public function getProducerFirstName() { return $this->producerFirstName; } public function getProducerMainName() { return $this->producerMainName; } 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,$firstName,$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,$firstName,$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 explains in detail the knowledge of PHP object-oriented and PHP inheritance related codes. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
Explain the code related to PHP object-oriented serialization and deserialization
How to use PHP methods Determine whether it is a mobile phone login (code)
How to achieve infinite classification through php loops and recursion
The above is the detailed content of Explain PHP object-oriented, PHP inheritance related code. For more information, please follow other related articles on the PHP Chinese website!