Blogger Information
Blog 24
fans 0
comment 12
visits 15517
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
静态绑定,拦截器作业
移动用户-5435854
Original
477 people have browsed it

5月1日作业
将本周的学习重点,如继承, 抽象类, trait笔记整理好
实例演示后期静态绑定的原理与实现
实例演示属性重载/拦截器的所有方法
实例演示方法重载/拦截器的所有方法
[选做]仿写课堂上的数据查询构造器, 多写几个方法试试看

  1. <?php
  2. abstract class work
  3. {
  4. public static function create() :self
  5. {
  6. return new static();
  7. }
  8. }
  9. class demo1 extends work
  10. {
  11. }
  12. class demo2 extends work
  13. {
  14. }
  15. $demo1= demo1::create();
  16. var_dump($demo1);
  17. echo '<br>';
  18. $demo2= demo2::create();
  19. var_dump($demo2);

属性查询拦截器

  1. class work
  2. {
  3. private $a;
  4. private $b;
  5. public function __construct($a,$b)
  6. {
  7. $this->a=$a;
  8. $this->b=$b;
  9. }
  10. public function __get($property)
  11. {
  12. return $this->$property;
  13. }
  14. }
  15. $work= new work('我是a','我是b');
  16. echo $work->a;
  17. echo $work->b;

属性检测拦截器

  1. class work
  2. {
  3. private $a;
  4. private $b;
  5. public function __construct($a,$b)
  6. {
  7. $this->a=$a;
  8. $this->b=$b;
  9. }
  10. public function __set($property,$value)
  11. {
  12. $method='get'.ucfirst($property);
  13. return method_exists($this,$method)?$this->$method():null;
  14. }
  15. public function seta($value)
  16. {
  17. return mb_substr($this->a,0,2);
  18. }
  19. public function setb($value)
  20. {
  21. return $this->b;
  22. }
  23. public function __isset($property)
  24. {
  25. return $property==='a'?isset($this->a):false;
  26. }
  27. }
  28. $work= new work('我是a','我是b');
  29. echo $work->a='我是a';
  30. echo $work->b ='我是b';
  31. echo '<br>';
  32. echo isset($property->a)?'存在':'不存在';

静态方法拦截器和方法拦截器

  1. <?php
  2. class user
  3. {
  4. public function __call($name,$args)
  5. {
  6. printf('方法名:%s是,参数:[%s]',$name,implode(',',$args));
  7. }
  8. public static function __callStatic($name, $arguments)
  9. {
  10. printf('方法名:%s是,参数:[%s]',$name,implode(',', $arguments));
  11. }
  12. }
  13. $user =new user();
  14. $user->demo(1,2,3,4);
  15. echo '<br>';
  16. $user::demo(1,2,3,4);

感想:已经讲到上传文件了,刚开始学拦截器,有点跟不上了。而且也做不到举一反三,只能先模拟老师的了。感觉还是挺难的。希望自己能坚持下来。黎明前的黑暗?

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
1 comments
移动用户-5435854 2020-05-20 20:12:25
好的,谢谢朱老师
1 floor
Author's latest blog post