tags:

views:

51

answers:

2

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 {
    private $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?

A: 

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.

Dennis Haarbrink
Bad programming is writing large functions, slow algorithms or writing difficult to understand code. The quirky workings of a particular programming language are the fault of the designers not the users. Arguably it is PHP that is 'bad' as the syntax distinction between local, global and class members is a little blurry.
jax
The wordings 'bad programming' are probably not the best. What I meant to say was that it's just a programmer's mistake, and it can't be detected by a parser. Weird thing to say that PHP is bad because it distinguishes between local and object scope.
Dennis Haarbrink
A: 

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...

Ivar Bonsaksen
I am using PHPEclipse from http://www.eclipse.org/. I can't find this menu you are talking about. I have Window->Preferences->PHP->editor->code Assist. But that is all and they don't have the warnings you mentioned. Are these versions different?
jax
I am installing this now. What is the difference between this and the PHP PDT?
jax
Late warning, but I don't think they work well together, so you might want to install it to a fresh eclipse install...
Ivar Bonsaksen