Ok, guys. Here's something I've been thinking about for a while:
As it's possible to chain methods in PHP5, I wonder if it is possible to take the concept even further by in a smart way determining if a method is the last in the chain to be executed - and that's without utilizing a third method named getResult()
?
Normal method calling:
$myClass->dofirst(); // Data is returned from the dofirst-method
What I would like;
$myclass->dofirst()->sortOutputfromDofirstAndReturn();
The idea is that the second method, sortOutputfromDofirstAndReturn()
would prevent the dofirst()
method from returning, and instead perform the logic stated inside the second method, without needing a third method to bounce the return to the user.
Maybe a bit confusing so let me know if I need to clarify anything!
sortOutputFromDOfirstAndReturn
can only be called afterdofirst
returns, otherwise you don't have an object to call anything on in the first place. Sincedofirst
has already returned, how would anything in the world prevent it from returning retroactively? Also, why on Earth would you want to do this?