你需要使用extends
关键字来扩展你的接口,当你需要在你的类中实现接口时,你需要使用implements
关键字来实现它。
您可以implements
在类中使用多个接口。如果你实现了接口,那么你需要定义所有函数的主体,像这样......
interface FirstInterface
{
function firstInterfaceMethod1();
function firstInterfaceMethod2();
}
interface SecondInterface
{
function SecondInterfaceMethod1();
function SecondInterfaceMethod2();
}
interface PerantInterface extends FirstInterface, SecondInterface
{
function perantInterfaceMethod1();
function perantInterfaceMethod2();
}
class Home implements PerantInterface
{
function firstInterfaceMethod1()
{
echo "firstInterfaceMethod1 implement";
}
function firstInterfaceMethod2()
{
echo "firstInterfaceMethod2 implement";
}
function SecondInterfaceMethod1()
{
echo "SecondInterfaceMethod1 implement";
}
function SecondInterfaceMethod2()
{
echo "SecondInterfaceMethod2 implement";
}
function perantInterfaceMethod1()
{
echo "perantInterfaceMethod1 implement";
}
function perantInterfaceMethod2()
{
echo "perantInterfaceMethod2 implement";
}
}
$obj = new Home();
$obj->firstInterfaceMethod1();
等等...调用方法