Home > Article > Backend Development > PHP multiple interfaces with the same method_PHP tutorial
If there are multiple interfaces with the same method name and they are not inherited, PHP is not allowed
The following examples:
php;">
interface a{
public function x();
}
interface b{
public function x();
}
class c implements a,b{
public function x();
}
The following error is reported: Can't inherit abstract function b::x() (previously declared abstract in c)
If you want to implement different interfaces with the same method, you can implement it as follows:
php;">
Interface d{
public function x();
}
interface a extends d{}
interface b extends d{}
class c implements a,b{
public function x(){
echo "succ";
}
}