About PHP Object-oriented, PHP inheritance code

Source: Internet
Author: User
Tags php class
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.