PHP has a ticks feature, which can get called at the execution of each statement.
Using the ticks feature, my answer describes a class CStatemenTracer, which write a call trace alongside the execution of your application.
Might be a starting point.