Home > Backend Development > PHP Tutorial > Rewriting understanding in php_PHP tutorial

Rewriting understanding in php_PHP tutorial

WBOY
Release: 2016-07-13 10:17:17
Original
1180 people have browsed it

Rewriting understanding in php

We often hear the three major features of object-oriented: encapsulation, inheritance, and polymorphism, but there are many more features, so do we remember to rewrite? While studying, I simply recorded the medium rewriting method of PHP:

1) Let’s look at an example first to make it clearer


//Define parent class (can also be called base class)
class Goods {
public $goods_name = 'Goods:name';

public function sayName() {
echo $this->goods_name;
}

}
//Define a subclass (can also become an extension class)
class Book extends Goods {
public $goods_name='Book:name';
public function sayName() {
echo 'run in book';
}
}
//instantiate object
$b1 = new Book;

//Output run in book, because the subclass overrides the parent class’s sayName() method
$b1->sayName();

The next chapter summarizes the rewriting calls in php...

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/894186.htmlTechArticleUnderstanding rewriting in PHP We often hear the three major features of object-oriented: encapsulation, inheritance, polymorphism, but There are many more features, so do we remember to rewrite them? When studying, simply...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template