php抽象类使用要点与注意事项分析,php抽象
本文实例分析了php抽象类使用要点与注意事项。分享给大家供大家参考。具体分析如下:
php抽象类使用要点与注意事项如下:
1、用 abstract 来修饰一个类,那么这个类就是抽象类;抽象类绝对不能被实例化,即$abc = new 抽象类名();会报错。
2、用abstract 来修饰一个方法,那么该方法就是抽象方法;
3、如果类中有一个抽象方法,那么该类就必须定义为抽象类;但反过来,抽象类里并不一定要有抽象方法。另外,抽象类里也可以有普通方法。
4、抽象方法不能有方法体。即abstract function abc();------后面不能加大括号{.........}。
5、一个类继承了某个抽象类,那么,它必须实现抽象类中所有的抽象方法(除非,它也这些抽象方法声明为抽象的,相当于抽象类继承了抽象类)。
抽象类简单实例:
<?php abstract class Animal{ public $name; protected $price; abstract function cry(); } class Dog extends Animal{ function cry(){ echo "汪汪..."; } } $abc = new Animal(); ?>
希望本文所述对大家的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

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)