You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
775 B

<?php
/*
* 接口是一种特殊的抽象类,所以接口时一种类
* 一个子类可以同时继承多个接口
* 接口里不能有变量,只有常量和抽象类
*/
//定义一个接口
interface animal
{
const eyes = 2;
const foots = 4;
function eat(); //抽象方法
}
interface pet
{
const name = 'lucky';
function run(); //抽象方法
}
class dog implements animal, pet //继承多个接口animal和pet
{
function eat()
{
echo "狗吃骨头".'<br>';
}
function run()
{
echo "狗跑去操场".'<br>';
}
}
$adog = new dog();
$adog -> eat();
$adog -> run();
?>