开发者

PHP strict code validation

I use PHPClipse for my PHP development. It has some code highlighting and some other validation such as forgetting to put a ';' at the end of a statement or forgetting '}' etc. I find it is easy to make a mistakes, for example

class foo {
    priv开发者_运维问答ate $test;

    function __construct() {
        $test = new stdClass;
        $test->myVar = "hello";
    }

    function getTest() {
        echo $this->test->myVar;
    }
}

This should have been $this->test = 6;

In code when things like this happen in conditionals such as if else the only time you realise is when the else statement executes which might be after the software was delivered to clients.

Other examples may be displaying a warning when a function from an abstract class is not implemented.

Is there a way, particularly in Eclipse, that you can turn on some sort of STRICT validate which highlights anything that might be a little dubious?


If you're using the PHPEclipse version from http://www.phpeclipse.com/ there should be some code analysis options under "Preferences / PHPeclipse / PHP / PHP Parser -> Style"

You can select warnings for uninitialized variables and unreachable code.

I'm not sure if there are anything similar available for the PHP Development Tools Project http://www.eclipse.org/pdt/

No checkbox for dubious code, though...


Warnings when using a local var instead of object var is not something you should expect from your editor, that's just bad programming.

I know for a fact that Zend Studio does a pretty thorough analysis on your code, for example warning you when you forget to implement a certain method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜