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.

38 lines
775 B

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