Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Handler
- {
- public function getHandler()
- {
- return 'some handler';
- }
- public function getFile()
- {
- return 'some file';
- }
- }
- $handler = $class->getHandler();
- $file = $class->getFile();
- public function getHandler() {
- // {
- // ...
- // возможно блок каких-либо действий
- // ...
- // }
- return $this;
- }
- class TestClass {
- public static $currentValue;
- private static $_instance = null;
- private function __construct() { }
- public static function getInstance() {
- if (self::$_instance === null) {
- self::$_instance = new self;
- }
- return self::$_instance;
- }
- public function toValue($value) {
- self::$currentValue = $value;
- return $this;
- }
- public function add($value) {
- self::$currentValue = self::$currentValue + $value;
- return $this;
- }
- public function subtract($value) {
- self::$currentValue = self::$currentValue - $value;
- return $this;
- }
- public function result() {
- return self::$currentValue;
- }
- }
- $result = TestClass::getInstance()
- ->toValue(5)
- ->add(3)
- ->subtract(2)
- ->add(8)
- ->result();
- echo $result; // выведет 14
- $file = $$handler->getFile();
- $function_name = 'getHandler';
- $result = $file->{$function_name}();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement