views:

77

answers:

3

As a developer that's used to static typing I usually let the compiler tell me if the code is correct, logic flaws excluded of course. But when refactoring PHP I find it is VERY hard to know that my code is correct.

There always seem to be some lingering reference to some method or member somewhere that get's broken and doesn't show up until runtime. Even when using the limited refactoring support in Zend Studio things tend to get broken somehow.

Due to the dynamic nature of the language itself, I understand it is a hard problem. But are there any tools out there to statically verify PHP code so that I know that it is okay before runtime? I don't want to see any more "Undefined property" error messages.

+2  A: 

I would recommend @viraptor's solution for preventing your current problems.

Here is some information on Static Analysis and Refactoring in PHP.
Static Analysis

http://strategoxt.org/PHP/PhpSat

PHP Refactoring

http://stackoverflow.com/questions/19758/tools-for-php-code-refactoring

Robert Greiner
+5  A: 

Write tests for your code (http://www.phpunit.de/), setup a continuous integration server, run UI tests (http://pear.php.net/package/Testing%5FSelenium/). With enough testing, you will find your problems straight after you commit bad code. Just keep the test code coverage high.

That's one of the main points of unit tests - you can refactor your code without actually breaking it, because you check all functionality after every change.

viraptor
+1 I agree, nice answer.
Robert Greiner
PHPUnit actually offers integrated Selenium testing without needing to pull in that PEAR package. It's really slick.
IanGreenleaf
A: 

unit tests. i'm the author of Testilence

just somebody