I cannot find a simple example about my question above: how can i detect the end of a method chain?
I’m just looked Zend_Db_Select for example but this one is too complex for this simple question i think.
Is it possible to catch the ‘end’ of a method chain in PHP?
thanks,
fabrik
No. This is not possible.
Zend_Db_Selectdoes not detect the end of the method chain. Every method you chain just returns$thisand when you stop chaining, you stopped chaining. There is no magic something that says: Hey, this is the end of the chain.Example:
If all methods
return $this, then$foowill contain the result ofchain(), so$thisagain. You can keep on chaining from there. Of course, the methods will do other things besides returning$this, e.g. set internal state – but that’s really all there is about Method chaining.If your code needs to know that it has reached the end of a chain, you would have to setup the chain before running it, e.g. Chain of Responsibility pattern.