views:

79

answers:

1

Is there any tool by which you can visualize the sequence of PHP code such that you can avoid mistakes such as here?

I had an idea that the code later in my PHP code will overwrite the code at the beginning. However, this was not the case in my case.

+2  A: 

I'm not sure I truly understand the question, but one solution might be to use a debugger ; a nice way to do that is with

  • The extension Xdebug, which can be used as a debugger
  • and some graphical IDE that integrates some debugging tools, like Eclipse PDT

Both of those are free, btw.

With those, you can do step by step, set up breakpoints, watch the content of variables, view stack traces, ... And it works both for Web and CLI scripts ;-)

Of course, it means having Eclipse running on the machine you are executing your script... But if you are executing it on your development machine, you probably have a GUI and all that, so it should be fine...
(I know that, for web applications, you can have Eclipse running on a different machine than the one with the PHP webserver -- that's what is called "remote debugging")


Obviously, you probably won't be doing that on your production server, but, as long as you are on your development machine, using a debugger sometimes really helps understanding what the frak is going on ^^

I've been using Drupal these last few month ; using a debugger was sometimes the only "sane" way of understand what called what and how ^^


Disclaimer : to be honnest : a large part of this answer is a re-post of an answer I did to another question a few days ago.

Pascal MARTIN
Good point about Eclipse! - EasyEclipse for PHP seems to be useful too.
Masi