CHAPTER 15

image

Abstract

An abstract class provides a partial implementation that other classes can build upon. When a class is declared as abstract it means that the class can contain incomplete methods that must be implemented in child classes, in addition to normal class members.

Abstract methods

In an abstract class any method can be declared abstract. These methods are then left unimplemented and only their signatures are specified, while their code blocks are replaced by semicolons.

abstract class Shape{  abstract public function myAbstract();}

Abstract example

To give an example, the class below has two properties and an abstract method.

Get PHP Quick Scripting Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.