Search code examples
phpmethod-chaining

PHP - determine last function-call from chained function-calls


When using chained functions, is there a way to determine if the current call is the last in the chain?

For example:

$oObject->first()->second()->third();

I want to check in first, second and third if the call is the last in the chain so it saves me to write a result-like function to always add to the chain. In this example the check should result true in third.


Solution

  • As far as i know it's impossible, i'd suggest to use finishing method like this:

    $oObject->first()
      ->second()
      ->third()
      ->end(); // like this