Question Details

Browse

PHP Code Analysis tool

By chanda - Jun. 09, 2007

Hi - I have just inherited a large php project, and the documentation is sparse. Also, there are a lot of queries that need to be optimized and urls that need to be tweaked. I am looking for an easy way to analyze the code using an 'ideally' free/opensource product. I am also contemplating just writing an analyzer myself that will go through the spider the files and dump out a report. Any ideas of tools I could use?


Answers

Add Answer
  1. By sunarm on Jun. 11, 2007

    Take a look at Zend Studio. It is not free but it has some code analysis features like flagging possible errors (unused variables, single use variables for possible typos and others)

    2 Votes
  2. By mfoley on Jun. 12, 2007

    For real basic tests first, you can just run php -l . This will point out some basic compile time errors. There are a few other tools like RATS and SWAAT that mainly check for security vulnerabilities.

    1 Votes
  3. By mfoley on Jun. 12, 2007

    I had a similar task, btw, and spent some time looking at the tools mentioned above, along with some free trials of commercial tools like Fortify. Ended up doing what you were thinking of - writing a quick analyzer for specific insight of queries used across the files. Dumped the results into a db so I could check on progress as we changed urls across the site from dynamic to static.

    1 Votes
  4. By w_brad on Jun. 25, 2007

    You can also spend some time using xdebug, and view the output in kcachegrind. Both of these are open source. xdebug had some issues with the zend optimizer, so you might need to turn that off when you use it. Another word of caution - xdebug log files might be left on, and depending on how aggressively you are logging, those logs could grow very fast! A good way to do this - set up your code, and run it a few times - run a smoke test or something. Then analyze the output. Following that, you can add your custom statements and analyze flow that way. Once you know the major files and methods being called, you can dig deeper. Hope this was of use.

    1 Votes
Share your knowledge