I need a PHP tool, an extension or something, that will let me analyse all the code being executed in a PHP script dynamically (not a static analysis tool), for example:
- I have an interface with some methods and some classes which implement this interface, I would need to intercept a method call of an interface's method at runtime, see which implementation of the interface has called the implemented method (the class with the namespace), what are the arguments values, what does the method do, what is the returned value, what was executed before the call of this method, what is going to be executed after, etc...;
- I have an object instance which writes and reads its properties, I would need to intercept property read/write, variable assignment, in a fancy way as described for the methods above (see what was executed before, what is going to be executed after, etc...);
- Intercept a statement e.g. an
echo
statement, see what happened before the statement, what is the expression of the statement (with variables interpolation), what is going to be executed after this statement; - Analyse an if-else, if-else if, for, while, do-while, case-switch, etc... condition in order to determine what operands were used and which were their values, what operators where used, etc...
So, something like this. Is it possible? I thought it could be implemented using PHP ticks
, but it seems to me a little bit unsuited for the purpose or better impossible to achieve the aims (if I have a declare(ticks=1)
and I register a tick handler, I can call it every time a statement is executed, but not for ifs, fors, whiles, etc..., and I cannot analyse the code being executed...)
Could you advise me something?
Thanks for the attention!
EDIT: I am not looking for a debugger, I need something I can deal with in code, e.g. analyse it and throw an exception if something is not as expected.