我们经常听到面向对象的三大特性:封装、继承、多态,但是还有许多特性,那么我们是否记得重写呢?在学习的时候简单的记录了下php中等重写方法:
1)先通过例子看下,这样更加明了
//定义父类(也可以称为基类)
class Goods {
public $goods_name = 'Goods:name';
public function sayName() {
echo $this->goods_name;
}
}
//定义子类(也可以成为扩展类)
class Book extends Goods {
public $goods_name='Book:name';
public function sayName() {
echo 'run in book';
}
}
//实例化对象
$b1 = new Book;
//输出run in book,因为子类重写了父类的sayName()方法
$b1->sayName();
下章总结下php中的重写调用...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools
