Tail Recursion class for php