The entire point of interfaces is to give you the flexibility to have your class be forced to implement multiple interfaces, but still not allow multiple inheritance. The issues with inheriting from multiple classes are many and varied and the wikipedia page on it sums them up pretty well.

Interfaces are a compromise. Most of the problems with multiple inheritance don't apply to abstract base classes, so most modern languages these days disable multiple inheritance yet call abstract base classes interfaces and allows a class to "implement" as many of those as they want.

Answer from Craig H on Stack Overflow
🌐
PHP
php.net › manual › en › language.oop5.interfaces.php
PHP: Object Interfaces - Manual
An interface, together with type declarations, provides a good way to make sure that a particular object contains particular methods. See instanceof operator and type declarations. Learn How To Improve This Page • Submit a Pull Request • Report a Bug ... PHP prevents interface a contant to be overridden by a class/interface that DIRECTLY inherits it.
🌐
W3Schools
w3schools.com › php › php_oop_interfaces.asp
PHP OOP Interfaces
A class that implements an interface must implement all of the interface's methods. <?php interface Animal { public function makeSound(); } class Cat implements Animal { public function makeSound() { echo "Meow"; } } $animal = new Cat(); $animal->makeSound(); ?> Try it Yourself »
Discussions

oop - What is the point of interfaces in PHP? - Stack Overflow
Interfaces allow you to create code that defines the methods of classes that implement it. You cannot however add any code to those methods. Abstract classes allow you to do the same thing, along w... More on stackoverflow.com
🌐 stackoverflow.com
Composercat - Graphical User Interface for Composer
I was gonna say "what's the point" but I guess if it helps more people who are scared of the command line use Composer, it's a good thing. More on reddit.com
🌐 r/PHP
45
60
February 5, 2017
Interface Vue to a PHP MVC framework?

In the case of an API, the front end and back end (in an ideal world) are completely separated. The only interaction between them would be through REST endpoints, and which backend you use would be irrelevant to Vue.

That said, my personal favorite tool for building the API is Laravel. Laravel has route shortcuts that automatically generate REST routes for a model. For instance with a Post model, it would create routes to fetch the posts, edit a post, create a new post, etc.

Then on the front end I use vue-resource to create resources that have the same routes as my Laravel API. so in JS I would run posts.update({id: 1}, {title: "New Title"});. Since both vue-resource and Laravel use REST practices, the routes match up perfectly.

Here is an example of a Laravel REST controller. It has update, store, delete, show, and index routes. https://github.com/jsiebach/angular-todo/blob/master/app/Http/Controllers/TodoController.php

In Vue then you would just create a resource to call those using var todos = Vue.http.resource("/api/todos/:id") and it maps to the same routes. todos.delete({id: 1}) for example. Vue resources: https://github.com/vuejs/vue-resource/blob/master/docs/resource.md

More on reddit.com
🌐 r/vuejs
5
3
April 4, 2015
Any reason to use an interface over an abstract class?
Multiple interfaces can be used on a single class, but you can only extend a class once Abstract classes can be more than just function definitions - it's a regular class, you just can't use it without extending it. Abstract classes are good when you have a base object that has children which will need to implement their own versions of some functions. The parent (abstract) can define all of the shared functions, and the children inherit all of those automatically. An interface requires you to code every one of those functions (or inherit them from another class). More on reddit.com
🌐 r/PHP
12
1
August 10, 2011
🌐
Reddit
reddit.com › r/php › i don't understand the usefulness of interface
r/PHP on Reddit: I don't understand the usefulness of Interface
March 25, 2015 -

Hi everyone.

I read some documentation about PHP Interfaces, but I still don't understand their usefulness. It talks about contracts with classes but what is a contract ?

As I understand them right now, they seem to describe functions that a class should absolutely have.

At first I though you had to write functions in the interface so they can be easily reusable between classes, but it appears that the core of the function is written in the class...

Please enlight me what is the point in this because I'm in the dark. It would be even better if you have a pertinent example to show me !

Thanks

Top answer
1 of 5
16
An interface is useful when you may have more than one class implementing the same types of operations. For example, suppose you are creating a cache system. You may create an interface, Cache, which defines what caches do. Next you may create several different implementations such as FileSystemCache, RedisCache, and MemcachdCache. The code that wants to cache information only uses the Cache interface. Maybe today the cache is implemented using the FileSystemCache object. As the website grows and traffic increases you see that a better cache system is required. Instead of rewriting all the places that are using the cache you can simply switch the creation of the cache from FileSystemCache to RedisCache.
2 of 5
7
but what is a contract ? A contract in this instance is your class saying it will have all the methods defined in the Interface. So lets take a simple interface. interface Car{ public function accelerate($peddlePercentage); public function brake($peddlePercentage); public function steer($degrees); public function getSpeed(); public function getDirection(); } Now, I am the driver and I get given a Toyota Camry class ToyotaCamry implements Car{} I dont need to look at the ToyotaCamry class to know how to drive it, why? because I know how to drive a Car. I know this Car will have a method to accelerate the car, a method to brake and a method to steer it. so if I wanted to do a test on the ToyotaCamry to see how fast it was I could do the following $toyotaCamry->accelerate(100); wait(10) echo $toyotaCamry->getSpeed(); // prints 60mph if I get given an exotic car, like a Lamborghini.. it is still a car $LambourghiniAventador->accelerate(100); wait(10) echo $LambourghiniAventador->getSpeed(); // prints 200mph Because the Lambourghini is much more powerful I have gone much faster, but how I did it was exactly the same. I could even make a function that does the test for me, it wont care what kind of Car I give it, only that It is a Car. function performAccelerationTestOnCar(Car $car) { $car->accelerate(100); wait(10); return $car->getSpeed(); } they seem to describe functions that a class should absolutely have. This is 100% correct, In the above example we described what functions and paramaters a class should have, so now My application can deal with any object that implements the class. At first I though you had to write functions in the interface so they can be easily reusable between classes, That is an Abstract Class, and a lesson for another day.
🌐
Zend
zend.com › blog › what-interface-php
PHP Interface | Interface in PHP With Examples | Zend
May 21, 2020 - A PHP interface defines a contract which a class must fulfill. If a PHP class is a blueprint for objects, an interface is a blueprint for classes. Any class implementing a given interface can be expected to have the same behavior in terms of ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-interface
PHP | Interface - GeeksforGeeks
November 3, 2018 - To implement an interface, use the implements operator as follows: ... <?php class MyClassName implements MyInterfaceName{ public function methodA() { // method A implementation } public function methodB(){ // method B implementation } } ?> ...
Find elsewhere
🌐
Simplilearn
simplilearn.com › home › resources › software development › complex programs with interface in php
Learn What is Interface in PHP with Example | Simplilearn
July 10, 2024 - A PHP interface defines a contract which a class must fulfill. If a PHP class is a blueprint for objects, an interface is a blueprint for classes. Read more for details.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Ash Allen Design
ashallendesign.co.uk › blog › using-interfaces-to-write-better-php-code
Using Interfaces to Write Better PHP Code | Ash Allen Design
January 2, 2024 - To allow a function or method to accept and operate on a parameter that conforms to an interface, while not caring what else the object may do or how it is implemented. These interfaces are often named like Iterable, Cacheable, Renderable, or so on to describe the significance of the behavior. Using PHP interfaces can have a number of benefits on the quality of your code.
🌐
Medium
medium.com › @maxalmonte14 › interfaces-in-php-dont-make-complete-sense-4e63be8e4233
Interfaces in PHP don’t make complete sense | by Max | Medium
April 19, 2019 - Indeed, but we are still talking about PHP 5.x, be patient, we are getting there. This problem is related to the previous one. As we already saw, an interface is a contract and must be enforced, we should remember this phrase because is !false. So, we have to question ourselves, are we really enforcing a contract if we don’t even really know what will a method return?
🌐
Tutorialspoint
tutorialspoint.com › php › php_interfaces.htm
PHP - Interfaces
In PHP, interfaces is used to define the contract that all classes have to follow. They allow several classes to use the same methods.
🌐
Medium
medium.com › @jmiqbal2019 › php-interfaces-a-guide-with-use-case-and-example-d519a6d78614
PHP Interfaces: A Guide with Use Case and Example | by Iqbal Hossen | Medium
November 8, 2024 - In PHP, an interface is a way to define a blueprint for classes, specifying methods that any class implementing the interface must have. Think of it as a contract between the interface and any class that implements it.
🌐
DEV Community
dev.to › norbybaru › how-to-use-traits-interface-and-abstract-classes-in-php-428b
How to use Traits, Interface, and Abstract classes In PHP - DEV Community
May 31, 2024 - To define a trait, use the trait ... MyClass class has access to the log method. Interfaces define a contract that must be implemented by any class that implements it....
🌐
LinkedIn
linkedin.com › pulse › difference-between-abstract-classes-vs-interfaces-php-usman-malik-fi9ef
Difference Between Abstract Classes Vs Interfaces in PHP
February 6, 2024 - Now, let's create classes that implement the Vehicle interface to represent specific types of vehicles, such as Car and Motorcycle: <?php // Implement Car class implementing Vehicle interface class Car implements Vehicle { private $name; private $color; // Constructor public function __construct($name, $color) { $this->name = $name; $this->color = $color; } // Implement start() method for Car public function start() { return "Starting car engine..."; } // Implement getInfo() method for Car public function getInfo() { return "Name: $this->name, Color: $this->color"; } } // Implement Motorcycle
🌐
PHP
wiki.php.net › rfc › traits-with-interfaces
PHP: rfc:traits-with-interfaces
Some or all of the trait’s implementing methods may be abstract, with the class including the trait providing the method implementation (similar to an abstract class that implements an interface). Concretely, Proposal 1 makes this code be valid and functional: <?php interface I { function foo(); } trait T implements I { function foo() { } }
🌐
GeeksforGeeks
geeksforgeeks.org › php › when-do-we-need-interfaces-in-php
When do we need Interfaces in PHP? - GeeksforGeeks
July 11, 2025 - Interface constants have the same restrictions as class constants. Interface methods are implicitly abstract. Example: ... <?php interface IMyInterface { const INTERFACE_CONST_1 = 1; const INTERFACE_CONST_2 = 'a string'; public function method_1(); public function method_2(); } ?>
🌐
Dayle Rees
daylerees.com › php-interfaces-explained
PHP Interfaces Explained
January 14, 2018 - Often, I'll begin by writing the interface first, if I know what the implementations are going to need to do. We know that caches need to read and write data, and we know that they use keys to identify the cached content. Right then, let's get writing. <?php interface Cache { public function write(string $key, $value): void; public function read(string $key); }
🌐
Scaler
scaler.com › topics › php-tutorial › interface-and-abstract-class-in-php
Abstract Classes and Interfaces in PHP - Scaler Topics
November 9, 2023 - They consist only of method signatures and constants, without any implementation. Classes can implement multiple interfaces but can inherit from only one abstract class. Both abstract classes and interfaces provide a way to enforce structure, standardize behavior, and promote code reusability in PHP applications.
🌐
PHP Tutorial
phptutorial.net › home › php oop › php interface
An Essential Guide to PHP Interface By Practical Examples
July 12, 2021 - An interface allows you to specify a contract that a class must implement. To define an interface, you use the interface keyword as follows: <?php interface MyInterface { //... } Code language: HTML, XML (xml)
🌐
Phppot
phppot.com › php › php-interfaces
PHP Interfaces - Phppot
July 3, 2022 - In PHP, the interface blocks declare a set of functions to be defined with a class to implement this interface. A class can extend more than one interface, thereby, we can simulate multiple inheritances in PHP.