Better Native PHP Syntax Support in Xcode

Better Native PHP Syntax Support in Xcode

I’m a big fan of the Xcode IDE from Apple. Unfortunately, it is myopically focused on development for iOS and Mac OS X, using Objective-C. A long time ago, it was a lot more open. You could find a variety of plugins that would extend its functionality to include the projects you work with, such as PHP syntax support, in Xcode outside of the Apple software ecosystem. But for the past several years Apple has made it difficult to extend the IDE beyond their intended purposes. I’m mainly a backend PHP developer, but I have been a long-time Mac user. This puts me in the position of having second-rate tools for the biggest reason I use my computer. Yes, there are IDEs for Mac OS X that focus on PHP, but they’re all cross-platform and written in Java, which is, itself, a second class citizen on the Mac platform.

I’ve suffered through using Netbeans, Eclipse, and PHPStorm for years, all the while yearning for a grown-up IDE like Xcode to do my job. No longer! With Xcode 4, Apple introduced CodeSnippets that allow a user to not only save commonly used code snippets to an easily accessible palette, but we can tokenize the snippets and define the prefix text to which Xcode’s autocomplete feature will respond. Type “fore…” and if you have a snippet called “foreach”, Xcode will offer up the helpful autocomplete list with your snippet. Hit tab or enter and the snippet will be inserted at the cursor. Hit tab again and you’ll be guided through the snippet’s tokens, one by one, allowing you to fill in the blanks.

With this in mind, I went to work creating over 5,000 snippets to cover the entirety of the PHP language. See my github repo here: https://github.com/tonyjohnston/PHP-Xcode-Autocomplete Now I have native-like autocomplete for Xcode. I start typing “str” and here’s what I see:

Screen-Shot-2013-06-07-at-6.21.41-PM Better Native PHP Syntax Support in Xcode

I tap enter and this is what results:Screen-Shot-2013-06-07-at-6.23.58-PM Better Native PHP Syntax Support in Xcode

I type “if” and Xcode presents this:Screen-Shot-2013-06-07-at-6.25.17-PM Better Native PHP Syntax Support in Xcode

Arrow down to ifelse and tap enter:Screen-Shot-2013-06-07-at-6.26.30-PM Better Native PHP Syntax Support in Xcode

Each of those blue rectangular ovals is a tabable token, just waiting for you to enter your specifics, just like Xcode’s support for Objective-C. It’s a huge advancement in the arena of Mac PHP IDEs. It took me about 6 hours to put this whole thing together so I’m sure that it can get better. Feel free to fork my GitHub repo for PHP Xcode Support and help make PHP a first class citizen on the only great IDE for the Mac.

10 thoughts on “Better Native PHP Syntax Support in Xcode

  1. You have to go to the Go menu in the Finder, select Go to Folder…, then type ~/Library/Developer. Unfortunately it’s a hidden folder for some reason, but it’s easy enough to get to.

  2. I can’t find Developer folder described in the path to install this. I am using Xcode 5.1 and I am using Mac book pro with OSX 10.9.2. Please guide I am new mac user.

  3. I’m a PHP Developer and recently got a Mac, now I was facing the problem of installing differents IDE for different purposes, this helps me a lot to choose the native development enviroment to continue my previous works, thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *