PHP code completion in TextMate
TextMate is a great all-round editor for simple (and some not-so-simple) tasks. For RoR, it's the dog's bullocks. I was, however, initially somewhat disappointed by its support for PHP.
Out of the box, TextMate doesn't support PHP code completion or provide you with an easy method of accessing the PHP documentation. I found, however, that you can easily configure it to do both of these things by downloading, installing and configuring the PHP Code Completion bundle.
Code completion
To set up code completion in TextMate, you must first download the PHP Code Completion bundle. As you can see, that link leads to an SVN repository.
To download and install the PHP code completion bundle, follow these instructions:
- Open Terminal
- Create a folder under /Library/Application Support/ called TextMate and a folder under that called /Bundles:
mkdir -p /Library/Application\ Support/TextMate/Bundles
- Switch to that folder:
cd /Library/Application\ Support/TextMate/Bundles
- Check out the bundle you want from the TextMate bundles repository:
svn co http://macromates.com/svn/Bundles/trunk/Bundles/PHPCodeCompletion.tmbundle
- If you had TextMate open during this, select Bundles → Bundle Editor → Reload Bundles.
Create a new PHP file and test out the code completion by typing the first few letters of a function name and pressing ⎋ (esc). If you press ⌥ F1 before code completion, you will see a list of similar functions and if you press it after completion, you will see some brief documentation on the function signature.
Documentation
The PHP docs are probably the best I've seen for any programming language. The online version with comments is especially useful. Although TextMate doesn't have a built-in feature in the default bundles to access this documentation, the PHP code completion bundle you just installed does. It does require some configuration though.
With the PHP code completion bundle installed, you can access the PHP documentation by pressing Shift F1. The first time you do this, you will see a message telling you that you need to configure your settings.
To configure the PHP documentation:
- If you don't already have it, download the PHP documentation (.tar.gz version) to your computer. I placed the .tar.gz file in
/Users/aral/library/PHP_Manual/and unzipped it there. The unzipped files appear in an html folder so the path I entered in my preferences (see Step 4, below) was/Users/aral/library/PHP_Manual/html/(do not leave out the trailing forward slash or else it won't work). Also, wherever you decide to place the documentaiton, make sure that none of the folder names on its path have a space in them. - Click the Edit Preferences link in the PHPCodeCompletion Documentation window to open the PHPCodeCompletion preferences file in TextMate.
- Comment out the line that reads
$phpcc_configured = FALSE;and uncomment the one that sets the same flag to true. - Set the path that you placed the documentation in to the value of the
$phpcc_manual_path_to_localvariable. - Save and close the preferences file.
Press Shift F1 on a function name to test out the documentation. If you see the familiar PHP web site appear, it means that you put the wrong path in the preferences file and that you are viewing the online docs as a backup. Of course, you may want to default to the online docs as they contain those invaluable user-submitted comments but it does make things slightly slower too.
That's it! You should now have code completion and documentation working for PHP in TextMate. Enjoy!
The PHP code completion in TextMate article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.

kevin
I have tried to svn this, but have been unable to get it to work, is it possible to please send the actual tmbundle to me? I keep getting an error that says svn: command unknown… Thanks for the writeup on the process, it sold me in wanting the code completion as I used to have that (almost standard with every editor on the windows side) though I am extremely new to Mac and am completely lost.
January 7th, 2007 at 5:03 amRob McMichael
You can download them from here
January 8th, 2007 at 12:47 pmhttp://www.imediatec.co.uk/tm/phpcc/
kevin
you are very kind, thanks very much.
January 8th, 2007 at 5:09 pmJohn Joyce
Hi, I downloaded and installed this bundle yesterday. The fuction lookup works. In fact everything seems to be working except for code completion.
Pressing the ESC key just gives me the system alert sound. “bonk”
Did I miss something? Do I need to have the local documentation installed to use code completion?
btw, getting SVN installed properly was a pain. packages out there install it to the system but don’t make it available to users. Had to find it, add it to the PATH then restart terminal to use it.
January 20th, 2007 at 12:25 amGeorge
Thanks for this post. I followed your instructions and it worked perfectly.
I’m relatively new to TextMate and am really loving it. It is this kind of feature that really sets it apart.
Thanks again!
March 27th, 2007 at 11:41 amBrian
Link is not working!!
May 6th, 2007 at 6:32 amBrian
Chris
Appears that this has been moved to the disabled bundles:
http://macromates.com/svn/Bundles/trunk/Disabled Bundles/PHPCodeCompletion.tmbundle/
May 7th, 2007 at 8:45 pmMatt
Thanks for the info, extremely helpful.
Here’s some updates for new readers:
1. Open Terminal, type ’svn’, if you see ‘-bash: svn: command not found’ you don’t have svn installed.
2. You can install Martin Ott’s svn package from http://www.codingmonkeys.de/mbo/
3. Follow steps 1 through 3 in this article
4. Type this in place of step 4 above (so it pulls from the new location):
svn co http://macromates.com/svn/Bundles/trunk/Disabled Bundles/PHPCodeCompletion.tmbundle/
May 18th, 2007 at 7:43 pmMatt
You need to put a “percent 20″ (a percent symbol % followed immediately by the number 20) in place of the space between the words ‘Disabled’ and ‘Bundles’ in previous svn checkout path (doesn’t appear to show up in the comments).
May 18th, 2007 at 7:46 pmNick
Installed last night with no problem…. Thank you this helps a lot.
May 22nd, 2007 at 4:36 amhsyn
Installed and had no problem at all, thanks
May 22nd, 2007 at 9:54 amAllan Odgaard
The plain PHP bundle supports completion, documentation lookup, and quick function synopsis (see Bundles → PHP → Help) — I have now removed the PHPCodeCompletion bundle from the repository to avoid confusion.
October 23rd, 2007 at 2:19 pmAral
Thanks for the update, Allan
October 23rd, 2007 at 6:51 pmAlexandra
Hy, I tried to install it but as long as i see none of the links are working!
March 30th, 2008 at 10:04 pmThanks!
Sam
@Alexandra Same problem here 404 on the URIs.
June 27th, 2008 at 7:47 amwza
where did that bundle go?
August 19th, 2008 at 11:29 amAdam
svn co http://macromates.com/svn/Bundles/trunk/Bundles/PHP.tmbundle/
September 3rd, 2008 at 8:22 am