A
A
Andrew2011-07-03 02:19:14
PHP
Andrew, 2011-07-03 02:19:14

PHP chaining

Hello!
Surely many of you are familiar with the Zend Framework and know about the use of the chain method in its classes. I would like to know if it is possible to somehow magically implement a class in php in such a way that ... So that I inherit from this class, write my methods and my magic class implements the chain, that is, it calls my method, processes and returns $this . It's not too lazy to write an extra line - so far it's just interest. It's important that I don't have to give class methods any prefixes or anything like that.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
gaelpa, 2011-07-03
@gaelpa

public function __call($method,$args){
   if (!in_array($method,$this->publicChainingMethods)) return null;
   call_user_func_array ( array($this,$method.'_real') , $args );
   return $this;
}

something like that?

A
Andrew, 2011-07-03
@xmdy

It's simple, for __call to work on existing functions, it is enough to make them private or protected, and they will be available for calling, but! Then there is a security hole - you can call any methods. How to solve the problem?

A
Andrew, 2011-07-03
@xmdy

Is it better to calm down and just do some prefix?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question