Digital Base – Blog » IDE

What is important in a PHP editor/IDE ?

Posted by Gijs Nelissen in Programming

I’ve been building websites for a while now. So i could say i am quite experienced although my (programming) knowledge is limited mainly focussed on building php applications. As a developer time is expensive, that’s why i am always looking for ways to speed up the web development process. A good start for fast & secure development is to have the right tools and the right feeling/connection with your editor.

On day-to-day basis i could say 80% of the time i have an open editor somewhere. Based on the amount of time you are “working together” with this piece of software, you could compare it to a marriage (although you shouldn’t trade wives as soon as you meet a younger, smarter and more beautiful girl).

I have a few expectations / requirements for a modern, good working editor

Decent Code Completion / Code Assistance

We all know word completion : auto completion involves the program predicting a word or sentence without the user actually having to type it in completely. This feature is used alot in text messaging (sms), email clients, browsers, search engines etc…

google_image_autocomplete

Autocompletion speeds up the entire process of typing a message, entering an address or, in our case, writing PHP code.

A decent source code editor analyses your source and suggests the function based on the first characters of the variable, function name or object. Most editors these days have code completion although they come in many flavours.

eclipse autocomplete

Larger web applications tend to use alot of classes & files. That’s what it is really important your autocompletion allows you to use an unlimited depth of super- & sub classes (inheritance). For this your IDE should have a decent understanding of the relation between classes. If in some case the code completion does not work for a certain object, you should be able to tell the editor which class your object belongs to, so it will allow you to use the code completion on next occurences of the same object/variable.

Code Documentation / PHPDoc

Another important aspect of code completion is documentation. It is very useful for a programmer to get as much visible feedback as possible about the method/function he is calling. For a php core function this should be a short summary what the function does, for custom methods/functions this would be the description as entered by the one that created the class/method.

eclipse_link

Next to that information it could be useful to show the return type and perhaps some information about the needed arguments. All these things should be integrated in the IDE, readily available when i enter the name of a method/class without opening a seperate manual or the php.net website.

When adding custom classes/methods/functions it is important that you document this code using phpdoc. Eclipse will then pick up this documentation and show it whenever you are using it somewhere else throughout your project.

Syntax Highlighting / Coloring

Code should look good. If you’re spending most of your time looking at code, it’s important to take care of your eyes. A good syntax highlighter highlights the different code to make a clear distinction between actual code, variables & documentation. Marking different type of elements in seperate colors will increase readability and help you understand a function faster.

Syntax highlighting also helps in finding errors in your code. Some editors mark incorrect code (missing delimiter, etc), this comes in handy when you are paying less attention. The editor will immediately show you you are doing something wrong…

Personally i prefer dark editors, many other programmers agree that this is alot better for your eyes. Next to that i find dark color schemes to be alot clearer and more beautiful to look at. TO give you an idea, this is what my eclipse looks like :

screenshot1

Code Bookmarks

When we are writing code it is important to keep track of important locations throughout the project. Code Bookmarks is the easiest way to do it.

A good implementation of bookmarks should allow you to easily switch to next/previous bookmark and give you an overview/listing of the current “bookmarks”.

screenshot3

If you look on the left side, you will see a small flag that marks the current line as being bookmarked.

screenshot7

Once you have these “code bookmarks”, its hard to code without them.

Smart/Quick opening

Now where did i put this code/file again ? Which class defines the foo() method ? Most of you will agree with me that opening the correct resource/file/method takes alot of time. A good editor should allow you to find/open everything you are looking for with a few keystrokes and (more important) without touching your mouse.

My favourite editor (Eclipse) allows you to use ctrl+shift+R to “open resource” and quickly find the file you were looking for.

screenshot8

This means i do not need to touch my mouse or open the “file explorer” to look for the file. Easy & Fast…

I know some people who use “grep -r ‘ methodname()’ to find the location of a method. I personally think this stinks. A good editor should contains some ways to easily open a file/method.

Class Outline

It’s easy to lose track of the variables/methods that are defined in a class. This is where the “outline view” comes in handy. This “outline” view will give you a the overview of every method/variable defined.

screenshot9

Double clicking a method will take you to this method. No search, no scrolling, no touching the mouse. In eclipse there is an even better way. Once inside a class you can use CTRL+O to get a quick outline with autocomplete functionality, finding the method you were looking for never was this easy…

eclipse quick outline

Thanks Eclipse :)

Platform Independance

If you are a regular reader of this blog, you will know we are using several linux flavours in our office. So for us it is very important t he same editor can be used on Windows & Linux platforms. Most “multi-platform” ide’s are based on java (zend, eclipse,…) but there are some other ide’s that have clients for both platforms.

Bug in Eclipse3.4 + PDT 2.0 (all platforms)

The Problem

After installing Eclipse 3.4 (codename : Ganymede ) and PDT 2.0 (PHP Development Tools ) as i explained in this post . You should have noticed a strange problem when opening/editing PHP files.

An internal error occured during “Selection Job Title”

After googling i found another user having the same problem but no real solution is posted, so here it comes .

The Solution

You need to install the latest version of DLTK (Dynamic Languages ToolKit ). Just download the files here , extract those to a local directory. Then launch eclipse, in software installs & updates (help menu) add a local site, and update DLTK.

After that just restart Ecipse (ganymede) and you can start using PDT.

Installing Eclipse 3.4 + PDT 2.x (nightly build)

I told you previously about my frustration getting eclipse 3.3 as a default in the latest ubuntu (Hardy Heron 8.04 ). It looks like they are not going to come up with a solution soon.

This guide will take you through the steps howto get the latest Eclipse together with PDT (PHP development Tools) running on your ubuntu box (Feisty or Hardy). Windows users, this guide will also help you throughout the process of installing our favourite PHP IDE (get that Zend ?).

Downloading all files :

get Eclipse 3.4

Goto the eclipse download site and pick one of the Ganymede (codename for 3.4) packages. As i only need eclipse for PHP development i went for the “Eclipse Classic” package (about 150MB).

get Eclipse PDT (2.0 nightly build)

The PDT download page offers alot of different packages. As we are using eclipse 3.4 we will have to go for the 2.x release. Select the “2.0.0 Nightly Build” option and download the package (about 6MB), you don’t need the PDT JUnit Plugin Tests and Automated Testing Framework so just select the first option.

move the files

Ok that’s it, now you should have 2 files :

  • eclipse-SDK-3.4-linux-gtk.tar.gz
  • org.eclipse.php_feature-I20080707.zip

Move those files to your home directory in a folder called “eclipsepdt”.

Unpacking everything:

Fire up a terminal window and move to the “eclipsepdt” folder

cd ~
cd eclipsepdt

Now unpack both files

unzip org.eclipse.php_feature-*.zip
mv eclipse pdt
tar -zxvf eclipse-SDK-3.4-linux-gtk.tar.gz

Now when you ls -all it should something like this :

Directory listing

Cleanup : remove archives:

Once that’s done, you will want to remove the archives (already unpacked).

rm eclipse*.tar.gz;rm org.eclipse.php*.zip

This should leave you with a clean folder containing all needed files. You should see something very similar to this :

 listing of eclipse directory (in home)

Correct Java Installation

Install Sun’s Java

Luckily java’s sun is in ubuntu’s package library, so we can use aptitude. If you don’t want Java 6, you can use Java 5 too (sun-java5-jdk. After this command it will ask you to accept a few terms & agreements, and press OK a few times, just follow instructions.

sudo apt-get install eclipse sun-java6-jdk

Tell Ubuntu to use Sun’s Java

This will install the required packages, however, Eclipse will run very
slowly since (by default) it will be using GNU’s java, not Sun’s. We now need to tell ubuntu to use Sun’s java as the default one (for those using java 5, replace
java-6-sun with java-1.5.0-sun).

sudo update-java-alternatives -s java-6-sun

Next, edit the JVM configuration file

sudo -b gedit /etc/jvm

and add the following line ON TOP

/usr/lib/jvm/java-6-sun

Tell Eclipse to use Sun’s Java

If you thought that this was it for the java part you are mistaking. There is a bug where Eclipse totally ignores the default java set in Ubuntu (bug 45347 ). That’s why you need to tell Eclipse explicitly to use the one you just installed.

sudo -b gedit /etc/eclipse/java_home

And add

/usr/lib/jvm/java-6-sun

On top of that file. Now we’re all set for the java part. Pfew…

Install PDT

As we downloaded Eclipse and PDT separately, you need to tell that Eclipse installation to install the PDT project libraries. So launch Eclipse

~/eclipsepdt/eclipse/eclipse

If all goes well you should see something like :

 eclipse ganymede splash

Feel free to scream if you want to. Press “OK” when eclipse asks you which workspace you want to open (unless you know what you are doing). This is really not important at this point in time, we need to get the PDT functionality running first.

Now go to Help (alt + H) => “Software Updates” and click the “Add Site” button (right side).

 eclipse add local repositiry

Now click the “Local” button (again right side) and navigatie to your home directory/eclipsepdt/pdt or just enter “~/eclipsepdt/pdt/” in the Location bar. Then confirm using the OK button (hmm i am making this one really dummy proof).

If everything goes well you should see something similar to this :

 eclipse software updates screen

Note the local folder (eclipsepdt/pdt) being on top.

Now check the PDT feature and click install (guess where ?). Eclipse will now try to locate and include all PDT dependencies (previously you had to resolve those dependencies manually). A few seconds later it should give you an “install” window mentioning “your original request has been modified”.

You are installing Eclipse PDT

This basically means that eclipse added the PDT dependencies to your installation queue . If you want to go on (why wouldn’t you if you came this far) just press the Next button. Next page, accept the terms and conditions. (i am letting this one slip from the screenshot gallery) and press Finish.

 PDT installation in progress

Now it’s time to go for a cup of coffee.

 Woohoo, PDT installed

That’s it, reload eclipse and enjoy the PDT features.

Some interesting links :

If you like this post, just help the community by making your voice count :