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
831 B

3 years ago
3 years ago
3 years ago
  1. <?php
  2. /*
  3. * 接口是一种特殊的抽象类,所以接口时一种类
  4. * 一个子类可以同时继承多个接口
  5. * 接口里不能有变量,只有常量和抽象类
  6. * 接口关键字interface,接口to类 implement
  7. */
  8. //定义一个接口
  9. interface animal
  10. {
  11. const eyes = 2;
  12. const foots = 4;
  13. function eat(); //抽象方法
  14. }
  15. interface pet
  16. {
  17. const name = 'lucky';
  18. function run(); //抽象方法
  19. }
  20. class dog implements animal, pet //继承多个接口animal和pet
  21. {
  22. function eat()
  23. {
  24. echo "狗吃骨头".'<br>';
  25. }
  26. function run()
  27. {
  28. echo "狗跑去操场".'<br>';
  29. }
  30. }
  31. $adog = new dog();
  32. $adog -> eat();
  33. $adog -> run();
  34. ?>