PHP: Abstract Classes & Interface

Abstract class and Interface play important role in object-oriented programming. In this lesson, we will try to learn how to use them in PHP.

What is an Abstract Class?

Abstract classes are classes which cannot be directly initialized. Other things to remember about this type of class are:

1. Abstract classes cannot create an object of abstract class
2. Abstract classes are created for inheritance purpose
3. Abstract classes can only be inherited by the child class

Abstract classes in PHP are similar to other OOP languages. You create an abstract class using the abstract keyword.

// #1-Abstract classes cannot create an object of abstract class.

abstract class man { public function run(){ return 1; } } $x = new man; // this will throw an error;
// #2-Abstract classes are created for inheritance purpose.

abstract class parentClass { public function run() { $msg = "Go Run"; echo $msg; } } class childClass extends parentClass { public function walk(){ $msg = "Go Walk"; echo $msg; } } $x = new childClass; $run = $x->run(); $run = $x->walk();

Learn English, Music and InfoTech

Our life here in Japan is so preoccupied with work, work  and work but that is not an excuse to stop learning new things that will somehow improve or “upgrade” our knowledge. You owe it to yourself!

I am now offering FREE English lessons, to Filipino children and adults living around Kamifukuoka area every Saturday between 7am to 3pm.

Personalized tutorials in Piano, Guitar, Software and Web Development, WordPress and other IT-related subjects are also offered at Y1,000 per hour.

For more information, please contact me.

Or fill-up the form below.

Meet the Dad.

Where does it come from?

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of “de Finibus Bonorum et Malorum” (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, “Lorem ipsum dolor sit amet..”, comes from a line in section 1.10.32.


Welcome to our Family Website!

What is Lorem Ipsum?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.