So this is an OOP
related question, but I was wondering if it was possible to call a function at the end of a chain, after it's all been run.
This was my code to run before wanting a function to be used explicitly when the chained methods are finished and I want to print
or opt
the content:
$something = $class('Paramater')->Foo(true)->opt();
Whereas, if we remove the end method we're just given the $this
returned from the Foo()
function, so:
$something = $class('Paramater')->Foo(true);
Would return us the actual class variable in $something
.
What I'd like to happen is at the end of the chain, there might be a magic method
that's called when the chain is finished.
So, $class('Parameter')->Foo(true)
would instead return the value of opt()
like used before, without needing the ending function to close the chain.
It's not so hard to simply add the chain-ending function at the end of a chain, but it helps the code look cleaner and easier to read without this chain ending function being used.