PHP 中的抽象类是什么? [英] What is an abstract class in PHP?
问题描述
PHP 中的抽象类是什么?
What is an abstract class in PHP?
如何使用?
推荐答案
抽象类是至少包含一个抽象方法的类,是一种没有任何实际代码,只有名称和参数的方法,并且已标记为抽象".
An abstract class is a class that contains at least one abstract method, which is a method without any actual code in it, just the name and the parameters, and that has been marked as "abstract".
这样做的目的是提供一种模板来继承并强制继承类实现抽象方法.
The purpose of this is to provide a kind of template to inherit from and to force the inheriting class to implement the abstract methods.
因此,抽象类介于常规类和纯接口之间.接口也是抽象类的特例,其中所有方法都是抽象的.
An abstract class thus is something between a regular class and a pure interface. Also interfaces are a special case of abstract classes where ALL methods are abstract.
请参阅 PHP 手册的本部分以获取进一步参考.
See this section of the PHP manual for further reference.
这篇关于PHP 中的抽象类是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!