Blogger Information
Blog 19
fans 1
comment 0
visits 13177
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2019.12.03前期基础知识梳理2--php培训第九期线上班
涤尘
Original
561 people have browsed it

案列

  1. <?php
  2. // 1. 创建类
  3. class Demo4
  4. {
  5. // 2. 添加类成员
  6. public $site;
  7. protected $role;
  8. public function getInfo()
  9. {
  10. return '我是: ' . $this->site . $this->role;
  11. }
  12. // 构造方法
  13. public function __construct($site, $role)
  14. {
  15. $this->site = $site;
  16. $this->role = $role;
  17. }
  18. public function __get($name)
  19. {
  20. $username = $_GET['username'] ?? '';
  21. if (isset($username) && $username === 'admin') {
  22. return isset($this->$name) ? $this->$name : '你真帅';
  23. } else {
  24. return '小朋友不能看哦';
  25. }
  26. }
  27. }
  28. // 3. 访问类成员
  29. $obj = new Demo4('宇宙最强', '战神');
  30. echo $obj->role;
  31. echo '<br>';
  32. echo $obj->name;

总结:对类与对象,继承/接口/抽象类更思路清晰一些,要记住关键词,还有oop流程,创建类,添加类成员,访问类成员!

手抄








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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!