What is an abstract class in PHP?

udaya picture udaya · Apr 1, 2010 · Viewed 106k times · Source

What is an abstract class in PHP?

How can it be used?

Answer

selfawaresoup picture selfawaresoup · Apr 1, 2010

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.

See this section of the PHP manual for further reference.