No, But we can use Interfaces and Traits to achieve the same goal in php.
We can define interface in pp using keyword interface as given here.
<?php interface InterfaceName { public function firstMethod(); public function secondMethod($name, $color); public function thirdMethod() : string; } ?>
We can define abstract classes in php. The main thing is abstract class cannot be instantiated only can be extended. And will have at least one abstract method.
<?php abstract class ParentClass { abstract public function someMethod1(); public function someMethod2($name, $color){ return $name.'-'.$color; }; abstract public function someMethod3() : string; } ?>
In php we do not have multiple inheritance. One class can extend from only one another class. So in this case we can use Traits. Methods defined in Traits can be used in Multiple classes.
// Defining a Trait. <?php trait MyTrait { // some code... } trait YourTrait{ // some code... } ?>
Now to use a trait you can call it as given below
<?php class MyClass { use MyTrait, YourTrait; } ?>
Note we are using multiple traits in class so class have access to methods from both Traits. Here is how you call functions from traits.
<?php trait MyTrait { public function message() { echo "OOP is Awesome! "; } } class Code { use MyTrait; } $obj = new Code(); $obj->message(); ?>