1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yuyi
  5. * Date: 2018/4/27
  6. * Time: 16:21
  7. */
  8. /**
  9. * Class myBase
  10. */
  11. class myBase
  12. {
  13. public function __construct()
  14. {
  15. }
  16. public function getData()
  17. {
  18. return [1, 2];
  19. }
  20. }
  21. /**
  22. * Class Filter1
  23. * @property myBase $next
  24. */
  25. class Filter1
  26. {
  27. private $_next;
  28. public function __construct($next)
  29. {
  30. $this->_next = $next;
  31. }
  32. public function getData()
  33. {
  34. $data = $this->_next->getData();
  35. //TODO
  36. array_pop($data);
  37. return $data;
  38. }
  39. }
  40. class Filter2
  41. {
  42. private $_next;
  43. public function __construct($next)
  44. {
  45. $this->_next = $next;
  46. }
  47. public function getData()
  48. {
  49. $data = $this->_next->getData();
  50. //TODO
  51. $data[] = 5;
  52. return $data;
  53. }
  54. }
  55. $b = new myBase();
  56. $b = new Filter1($b);
  57. //$b = new Filter2($b);
  58. var_dump($b->getData());

分类: web

标签:   php