Sr. PHP Programmer Question:
Download Questions PDF

In PHP what is the difference between a Class and an Interface?

Answer:

Interfaces do not contain business logic, only method signatures that define a template that any classes implementing the interface must contain. Lets take an auto mobile for example. If we were to create and interface for a car we would want to define a few methods like drive, stop, turn left , turn right. This mean that any vehicle that is a car (aka implements the interface car) must have methods for these things, If they do not PHP will throw an error. So if your car is an BMW , Honda or Ford it must be able to stop. How it stops is up to each car (or PHP class) but it must be able to stop. Technically we can decide not to use an interface for cars, but then some types of cars are not forced to have a "stop" method.

Download Senior PHP Programmer Interview Questions And Answers PDF

Previous QuestionNext Question
How to find the position of the first occurrence of a substring in a string?How do you load classes in PHP?