views:

955

answers:

11

Despite what some might say, I believe that code completion (aka Intellisense) is the second best invention when it comes to code editors (the first being syntax coloring). It really makes coding easier because I don't have to worry whether I named the function CalculateReportSums, ReportSumsCalculate or simply GetReportSums.

Unfortunately I have not yet found a code editor which would satisfactory implement this feature for PHP. And by "satisfactory" I mean "as good as Visual Studio for C#".

My first choice of text editor is Notepad++, but that only has a list of PHP's built-in functions, and it only appears after you hit Ctrl+SPACE. I've also tried Eclipse+PDT, which is better, but still often has hiccups, sometimes fails altogether for no apparent reason (no list available), and always appears only when I pause typing (setting the timeout to some small value causes the list not to appear altogether).

So - is there something better out there? Something that would be aware of all the variables in the current scope, that would be able to follow include()s, and would display the list in real-time as I type?

I know that PHP is a dynamic language and a perfect code-completion is impossible in principle (because you don't know what variables will be there until runtime), but it should still be possible to implement it to a fairly good degree - much better than what I've seen so far.

Added: To add a few minor points - I want the CC to be instantaneous, like in Visual Studio. I type a character, and the list shows at the same instant. I type another character and the list becomes half the size before I can even blink. Near-zero CPU usage, instantaneous results (all hail the Gods of caching!).

Also - I'm fine with documenting my functions and even variables in a special way. I prefer PHPLint syntax (because then I can check my code with it later), but other syntaxes will do as well. Forcing to do this is also good for your commenting discipline. :)

A: 

http://www.aptana.org/

Jim Schubert
That is based on the same PDT that Eclipse uses. Somehow I don't trust it...
Vilx-
Whats really annoying about Aptana, is it tries to secretly install its professional version demo with every auto-update. Thats a sure fire way to make me not ever want to give them a dime or use their product.
Brandon G
@Vilx: Aptana is available in either standalone or Eclipse plugin.@Brandon: That is quite annoying, but it hasn't stopped me from using it's functionality. I've even considered purchasing the pro version.
Jim Schubert
Nice. Thanks for warning me! :P
Vilx-
The professional version doesn't exist anymore - and since version 2.0 neither does native PHP support
codeinthehole
@codeinthehole: Yeah, I just saw that. I guess I should update everything.
Jim Schubert
@codeinthehole. Thanks for the update. Its been a few months since my last download.
Brandon G
+15  A: 

I have found that Netbeans has better code completion than Aptana. When I was working with codeigniter, Netbeans would code complete for my static methods in models where Aptana wouldn't.

Brandon G
Is it instantaneous, or do you have to pause typing? This is one of the things that annoys me most in PDT.
Vilx-
You have to pause for maybe half a second? If you keep typing the auto-completion list won't show up. I use NetBeans and have been fairly happy, so I've upvoted this.
Ray Hidayat
That's just it - you have to pause for that half-a-second. The same as in Eclipse. I don't like that. :P
Vilx-
`Ctrl - Spacebar` and the autocomplete dialog shows instantly.
jason
...which has the same level of "annoying" if not more. :)
Vilx-
I still think its probably the fastest one out there. The development thread indicates that it is continually getting faster for each release.
Brandon G
Maybe it can be configured to be instantaneous? Eclipse can - except it doesn't work.
Vilx-
In Eclipse, navigate to: `Window -> Preferences -> PHP -> Editor -> Code Assist` And you can configure the "Auto activation delay"
jason
As I said - it only works in theory. :(
Vilx-
I have no idea what you're talking about. It works fine. Which version of Eclipse and PDT are you using?
jason
Latest. If I set it to 0 (or 1, or something else small), the list doesn't appear at all.
Vilx-
Then set it to something reasonable. It's in milliseconds. Mine is at 200, and it's just perfect. Doesn't come up when I don't want it to, does if I do.
jason
I personally prefer the Netbeans and hitting cntrl space, which is second nature pretty quick. That way, the autocomplete doesn't cloud the code and hide everything else when I don't want it to. I don't want it in the way all the time trying to always figure out what I'm typing, and making it impossible to read the rest of my code. It should be there when I want it, but not be distracting.
Cryophallion
I guess I'm just used to Visual Studio and want the same behavior everywhere else too. There the autocomplete shows up instantly, and if I don't want it, I hit Esc, which has already become second nature to me.
Vilx-
`Ctrl - Space` for autocomplete *is* the same behaviour as VS.
jason
Yes, but the don't-show-while-I'm-typing *isn't*.
Vilx-
If you want Visual Studio behavior, why don't you use Visual Studio ? I'm sure there's some plug-in to work with PhP.
Arkh
On that note, have a look at this: http://www.jcxsoftware.com/vs.php
Brandon G
A: 

vim.

http://weierophinney.net/matthew/archives/123-Vim-7-code-completion.html

Also, looking at the recommended similar questions, I noticed there is already a good question discussing the different ways to use vim code completion.

http://stackoverflow.com/questions/1055084/word-code-completion-in-vim

icco
Does it also analyze my code or only shows predefined keywords?
Vilx-
I don't actually know. I assume not, but I don't use it, I just know it exists, sorry.
icco
A: 

You can try Zend Studio.

Alix Axel
+1  A: 

I use PHPEd (http://www.nusphere.com/) which has a workable version of this feature.

note: They have an offer listed on their front page. Ignore this. It has been ending tomorrow for at least 4 years now.

rikh
+3  A: 

You're right that intellisense is much more complicated in a dynamically typed language like php. Consider for example

  function get_foo($x) {
       return $x ? new abc() : new xyz();
  }

  get_foo(123)->... can your IDE autocomplete here?

Don't know about PDT, but Netbeans is unable to handle this, and phped requires 'get_foo' to be annotated in a special way.

I haven't yet tried the upcoming WebIDE from Jetbrains (http://www.jetbrains.com/webide/features/index.html), but looks promising in this regard (see screenshot).

stereofrog
I'm fine with documenting my functions in a special way (PHPLint synax preferred, but I'm not too picky). Requiring this for CC to work is good for commenting discipline. :)
Vilx-
WebIDE looks fine, I just wonder how instantaneous it is - they don't show that in screenshots. :(
Vilx-
Oh, oops, it's just a preview version that will expire in 45 days. Too bad. :(
Vilx-
Netbeans can handle this. Set a @return object in the methods javadoc. if you are going to call a method from a function that returns an object of unknown type, you should have an abstract class as the return type.
Brandon G
@Brandon: i don't think I "should" do anything to support an IDE. IDEs are there to help me do my job in the way I want. I'm not going to break my coding habits just because some ide isn't smart enough to handle them.
stereofrog
Fair enough, but if you are returning different objects based on a conditional, your ide won't know which object to complete code from and essentially, neither will you. Based on the example you gave me, if you try and call a method from abc thats not available in xyz and the method returned an xyz instance, you will get an error. This is why an abstract class is a good idea and has nothing to do with "supporting the ide". The ide is really supporting the dynamicness of PHP by allowing you to specify a return type in the doc, IMHO.
Brandon G
don't let IDE vendors fool you - they require you to use annotations and interfaces because their products won't work without them - not because it's a "good idea".
stereofrog
A: 

I take it you are on Windows. In windows I usually use phpDesigner (http://www.mpsoftware.dk/phpdesigner.php) which has pretty good CC. In linux, I use geany(http://www.geany.org/) or vim both of which have CC, in the later case, you will need to set it up. I found Eclipse to be too bloated and I got sick of waiting for it to startup. :\

agentile
+1  A: 

No doubt, use NetBeans, is very usefull and have a good intelisense (okay, not is perfect) but is better than Eclipse for example.

MCunha98
+1  A: 

Kimodo has good code completion, revealing not only the functions in PHP, but the stuff that you've got declared in the current context. Additionally, if you've properly documented your function or whichever, it displays that documentation as well!

John Fiala
+1  A: 

I recommend you netbeans .its free. it is available for all platforms, and mostly it is good for editing php, jsp, java, css, html, ... Good for SVN, mercurial, Plus you can integrate it easyly with kenai.com...

it helps with the IntelliSense kind of pop up.

believe me, i'm using it for php development and its the best suited ide i can find...

JSixface
A: 

I have yet to see anything top the Auto Completion that was in Zend Studio 5.x. I have tried later versions, which are built on Eclipse, and well might as well be using Aptana...

Unfortunately this means keeping windows with the XP or 2000 look since the Java GUI (the one Zend Studio was built on) screws up in Win7 Look, but for the features Zend 5 has, it is well worth it.

Not only will it auto complete known functions, it will autocomplete variables/functions you make, and not only for your current file, but any open file (and I think any in open project), and will auto suggest Class items as well.

Plus being able to run local inside Zend Studio itself for testing parts of code is great. If only it easily let you save to both local file system and upload to the server at the same time.... (I just let a FTP program running in the background that every 10 minutes will download any changes to the server).

Greg K