Tag Archives: Eclipse

XDebug and PDT highlight wrong line in Eclipse

After upgrading to Eclipse 4.4 (Luna) I started having problems debugging PHP files with XDebug. The problem is the code editor would highlight the wrong line when it jumped from one file to the next, but it would move to the correct line after stepping to the next line in the file. I was hoping the problem would be fixed in 4.4.1 (Luna SR1), but the problem got worse and the editor would only highlight the line with the break point and not move at all.

Luckily the bug has been fixed and is available in the PDT night builds, but not as a release yet. To get it add http://download.eclipse.org/tools/pdt/updates/3.3-nightly/ to Eclipse’s available software sites (Preferences -> Install / Update -> Available Software Sites) and install updates (Help -> Check for Updates).

More info here https://www.eclipse.org/forums/index.php/t/823451/

Found missing spell checker in Eclipse for PHP Developers

After a recent upgrade I discovered that spell checking had stopped working in Eclipse. The spelling configuration in preferences only displayed the less than helpful message ‘The spelling service is not installed’. I looked around for a missing Eclipse plug-in or something not installed in Linux but couldn’t find anything helpful. Finally I found a bug report that shed some light on the problem. Turns out the spell checking functionality is bundled with the JDT. When I upgraded I installed the new Eclipse for PHP Developers package which doesn’t include JDT and hence no spell checking. Installing JDT in Eclipse fixed the problem, but a more helpful message in the spelling preferences would have saved me a lot of time.

PHP Inline type hinting in Eclipse

For the most part type hinting works pretty well using PDT in Eclipse. It speeds up coding and the best part is Eclipse will automatically determine variable types from class definitions and DocBlock comments. Eclipse also supports inline type hints for when it cannot determine a variable’s type, but the format is a little different than normal DocBlock comments and I always end up having to search for examples when I need it. So I leaving myself a reminder here and hopefully it will be helpful to someone else as well.

This usually comes up when I’m iterating through a list of objects…

foreach ($arrayOfObjects as $object) {
    $object->property;
    $object->method();
}

It would be nice if Eclipse could help me out with the properties and methods for $object, but it has no way of determining type type of $object. Inline type hinting to the rescue…

/* @var $object \My\Object */
foreach ($arrayOfObjects as $object) {
    $object->property;
    $object->method();
}

Now Eclipse will happily auto complete methods and properties for $object. The part I always forget is that this is not a DocBlock comment (one asterisk /* instead of two /**) and that the variable’s type comes after the variable’s name, which is the opposite of other PHPDoc tags. Eclipse is very particular about this and type hinting will not work if it’s not right. Another important thing to keep in mind is that types in comments must include the complete namespace including the leading slash.