Blogger Information
Blog 52
fans 0
comment 3
visits 42458
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php学习:接口与trait
王小飞
Original
657 people have browsed it

接口的多继承

  1. // interface 接口
  2. interface iUser
  3. {
  4. // 接口常量
  5. const ZHANG = 'admin';
  6. const MIMA = '123456';
  7. }
  8. //extends 继承iUser
  9. interface iUserqita extends iUser
  10. {
  11. const MIBAO = '18868689999';
  12. const YOUX = '123456@qq.com';
  13. }
  14. //实现多继承
  15. interface iUserz extends iUserqita
  16. {
  17. // 接口方法
  18. public function write();
  19. }
  20. // 实现类
  21. class User implements iUserz
  22. {
  23. // 必须实现接口中的抽象方法
  24. public function write()
  25. {
  26. return ' 账户: ' . iUser::ZHANG . ' 密码: ' . iUser::MIMA ;
  27. }
  28. //增加一个方法
  29. public function write2()
  30. {
  31. return ' 密保手机: ' . iUserqita::MIBAO . ' 邮箱: ' . iUserqita::YOUX ;
  32. }
  33. }
  34. echo ( new User)->write();
  35. echo '<hr>';
  36. echo ( new User)->write2();

trait 代码复用

  1. trait tUserdy
  2. {
  3. // trait 定义一个方法 格式化打印
  4. public function write()
  5. {
  6. $props =get_class_vars(__CLASS__);
  7. printf('<pre>%s</pre>', print_r($props, true));
  8. }
  9. }
  10. class iUsers1
  11. {
  12. //多复用trait tUserdy
  13. use tUserdy;
  14. //公开属性
  15. public $zhang = 'admin';
  16. public $mima = '123456';
  17. public $xingqi = ['刷抖音','看新闻','听鬼故事'];
  18. }
  19. class iUsers2
  20. {
  21. //多复用trait tUserdy
  22. use tUserdy;
  23. //公开属性
  24. public $zhang = 'xiaofei';
  25. public $mima = '516156151';
  26. public $xingqi = ['玩游戏','唱歌','看电影'];
  27. }
  28. (new iUsers1)->write();
  29. (new iUsers2)->write();

总结:老师课程里面讲的接口连接数据库的两种方法,和四种操作大体能看懂,但是里面连接数据库和执行具体内容看不懂,所以举例就举了个简单的,~~(>_<)~~

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:等学到数据库知识就会了
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post