Weekly Webtips
Published in

Weekly Webtips

That one question that is asked in every PHP interview

I am a PHP programmer and have been on many job interviews. I noticed that on each of them one question always came up.

That question is:

What’s the difference between interface and abstract class?

The answer to this question is simple and proves the candidate’s familiarity with object-oriented programming.

So let’s compare these two:


  • It cannot contain any functionality. It only contains definitions of the methods.
  • The derived class MUST provide code for all the methods defined in the interface.
  • Completely different and non-related classes can be logically grouped together using an interface.

To declare interface use interface keyword

interface ButtonClick {
public function setValue($name,$var);
public function getData($jsonData);

Abstract class

  • It can provide some functionality and leave the rest for the derived class.
  • The derived class may or may not override the concrete functions defined in the base class.
  • A child class extended from an abstract class should logically be related.

To declare class to be abstract just simply abstract before class keyword

abstract class MyAbstractClass {
//your code goes here

If you like this then share it with your friends to help them.

Also let me know in the comment section.

Connect with me on Twitter




Explore the world of web technologies through a series of tutorials

Recommended from Medium

Rapid App Development with Azure Spring Cloud Enterprise

How to back-up Postgres database on Linux using cronjob — boobo94

0–9999 counter module using Arduino UNO

Build and Test Your Game

Download Iphone 6 Driver For Windows 10

8 Fun Facts About Ajax That Will Help You with Your Assignment

Log request and responses of REST APIs in SpringBoot

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hilal Ahmad

Hilal Ahmad

A Software Engineer with 3 years of experience in Software development. Visit me at https://about.me/hilalahmad

More from Medium

Stop writing the same code. Generate it.

Sample of Jinn definition YAML for a simple Blog application

Php 8.1 New Features — Fibers

Node.js vs PHP. Choosing Between Modernity and Tradition

Two years from PHP “dying”: There are other tools