//声明接口 interface iTest{ public function test(); //定义方法无需实现 public function sayHi($username); } //实现接口 class Test1 implements iTest{ //实现方法 public function test(){ echo 'this is a test<br/>'; } public function sayHi($username){ echo 'Say Hi to '.$username.'<br/>'; } }
interface iA{ public function test00(); } interface iB{ public function test11(); } interface iC{ public function test22(); } //集成多个接口 class Test2 implements iA,iB,iC{ public function test00(){ echo '00000<br/>'; } public function test11(){ echo '11111<br/>'; } public function test22(){ echo '22222<br/>'; } }
class Parent1{ public function hello(){ echo 'hello parent<br/>'; } } class Child1 extends Parent1 implements iA,iB{ public function test00(){ echo 'qqqq<br/>'; } public function test11(){ echo 'wwwww<br/>'; } }
//接口可以继承另外的接口,可以继承多个接口 interface iD extends iA,iB,iC{ const PI=3.14; const COUNTY='China'; public function test33(); } class Test3 implements iD{ public function test33(){ echo 'this is a test33...<br/>'; } public function test00(){ echo '00000a<br/>'; } public function test11(){ echo '11111b<br/>'; } public function test22(){ echo '22222c<br/>'; } }