Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. class Handler
  2. {
  3. public function getHandler()
  4. {
  5. return 'some handler';
  6. }
  7.  
  8. public function getFile()
  9. {
  10. return 'some file';
  11.  
  12. }
  13. }
  14.  
  15. $handler = $class->getHandler();
  16. $file = $class->getFile();
  17.  
  18. public function getHandler() {
  19. // {
  20. // ...
  21. // возможно блок каких-либо действий
  22. // ...
  23. // }
  24. return $this;
  25. }
  26.  
  27. class TestClass {
  28. public static $currentValue;
  29.  
  30. private static $_instance = null;
  31.  
  32. private function __construct() { }
  33.  
  34. public static function getInstance() {
  35. if (self::$_instance === null) {
  36. self::$_instance = new self;
  37. }
  38.  
  39. return self::$_instance;
  40. }
  41.  
  42. public function toValue($value) {
  43. self::$currentValue = $value;
  44. return $this;
  45. }
  46.  
  47. public function add($value) {
  48. self::$currentValue = self::$currentValue + $value;
  49. return $this;
  50. }
  51.  
  52. public function subtract($value) {
  53. self::$currentValue = self::$currentValue - $value;
  54. return $this;
  55. }
  56.  
  57. public function result() {
  58. return self::$currentValue;
  59. }
  60. }
  61.  
  62. $result = TestClass::getInstance()
  63. ->toValue(5)
  64. ->add(3)
  65. ->subtract(2)
  66. ->add(8)
  67. ->result();
  68.  
  69. echo $result; // выведет 14
  70.  
  71. $file = $$handler->getFile();
  72.  
  73. $function_name = 'getHandler';
  74. $result = $file->{$function_name}();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement