Web Development With PhpStorm
A while ago I changed my main IDE from eclipse to Sublime Text 2. I really enjoyed working with it and even wrote an article about what it's like to do web development with Sublime Text 2.
The main reason why I used Sublime Text was for speed and simplicity, Sublime Text at it's basic level is a text editor, which has been extended into an IDE. Everything about it was built for speed, which makes sublime one of the quickest and easiest text editors to use. Along with this speed sublime text 2 has 1000s of additional open source plugins, with a massive community of developers contributing to new plugins all the time.
Sublime Text 2 can also be used for multiple languages from web development to software development.
Recently I have made the switch to PhpStorm for my web development and I will not look back, in this article I will go through the reason why I've switched to PhpStorm.
IDE vs Text Editor
To start with PhpStorm is a fully featured IDE, with this you get many features that you don't get from a text editor. At it's basic level Sublime Text is just a text editor, but using the massive amount of plugins available to add more features turning it into an IDE.
One difference between an IDE and a text editor is that an IDE will index the files and code which improves the inbuilt intellisense and code completions. The benefit of this means that the IDE understands the code you are writing and will give you hints on how you can complete the code, making you more efficient.
Another benefit of indexing the code is that it allows you to click through into a class or function to see exactly what the code does. All you have to do is hold the ctrl button and click on a function to step into it.
IDEs can benefit with refactoring the code, as the code is indexed it will understand where a variable/function is being used, therefore if this is renamed then the IDE will be able to rename all mentions of the variable/method.
Syntax checkers come inbuilt into IDEs these will check your code for any errors, showing you any mistakes you make in your code.
Popular PHP IDE's
There are lots PHP IDE's and I wouldn't say that there is simply one perfect IDE that everyone should use. All IDE's are different and each have their own strengths and weaknesses, the best thing to do is try a few and see which ones you best get along with.
Some of the most popular PHP IDEs are:
- Zend Studio
- Sublime Text
In February 2014 SitePoint ran a survey to find out what was the best PHP IDE on the market.
After over 4000 entries into the survey the overall winner of best PHP IDE with 39.8% of the votes went to PhpStorm.
This survey was done for what people prefer for both personal and business use. The argument for why PhpStorm is the most popular is due to the fact that it is packed full of features but is still very fast compared to other IDEs on the market.
In second place is Sublime Text, again due to the fact that it is a very fast program, with it's massive community and plugins available you can do a lot of things with this program.
PhpStorm costs money, for people that don't want to pay for an IDE seem to use the third position choice, Netbeans. It's a free alternative to using PhpStorm it has similar functionality to PhpStorm but does not support as many languages. It is also a lot slower than PhpStorm and does use more resources on your computer, but it is still a very good IDE.
In this article I'm going to talk about just some of the best features of PhpStorm and how it compares to other popular IDEs such as Sublime Text.
Go To Anything Panel
Sublime text has a nice feature where you can press ctrl + p to bring up a panel where you can fuzzy search for any file in your project.
PhpStorm also has a similar feature, where you can go to anything, the keyboard shortcut is double tap shift. You can also go directly to a file if you know the name of the file that you want you can quickly search for it by pressing crtl + shift + n. This bring up a small window where you can type in the file name, it will perform a fuzzy search and bring back any files that match your search term.
If you know the class name you are searching for press ctrl + n, this will bring up a small window for you to type in the class name. This will then search your entire project for classes of this search term.
This is probably my favourite feature of sublime text 2 and once you use it and see the advantages of it in development you will wonder how you ever lived without it.
Multi cursor allows you to make multiple changes at the same time, for example if you have wrote a couple of lines with a variable but want to change the variable name. Instead of using a find and replace feature you can quickly use multi cursor to search for this variable and change all of them at the same time.
To use multi cursor all you have to do is use the keyboard shortcut ctrl + d, when your cursor is on a word pressing ctrl + d will highlight the word, pressing ctrl + d again will look for the next occurrence of this word and create another cursor on this word.
This makes it so easy to change multiple variable or functions all at the same time. It doesn't seem like a WOW feature but when you use it and see how much time it saves you will wonder how you ever worked without it.
This was actually one of the features that stopped me moving away from sublime for so long, as from version 8 of PhpStorm they have released there own multi cursor functionality. It works exactly the same way as sublime but the shortcut to get started with this is alt + j.
Sublime text 2 allows you to edit the system config files to customise everything about how the program works. You can change everything from font size, tab spaces, use of spaces in tabs, indent guides, trim the end of the line on save, word wrapping and lots more.
With PhpStorm you can not only customise the configuration of the IDE but you can also customise the code completion of the IDE. The settings for PhpStorm is handled by a settings menu giving you everything you need to change on the IDE, as there are so many settings to change it also provides you with a search functionality to find what you need.
When I first started using PhpStorm this took some time to get used to, you don't actually need to hit ctrl + s to save your files. PhpStorm will watch your files and any changes made will automatically be saved. I'm still trying to get out of the habit of pressing ctrl + s to save the file.
Local File History
If you are worried about the auto save functionality saving things you don't want it to, PhpStorm has inbuilt functionality to record all local changes you have made to your file, so if you have made a mistake instead of clicking undo until your back you can browse the local history to find a version of the code you are happy with.
Create Your Own Snippets
You can create your own code snippets to use in the different files types in your project, code snippets in PhpStorm are called Live Templates. To create a new Live Template you need to navigate to the settings area under the File -> Settings menu, in the settings window there is a menu on the left hand side, search for Live Templates and select the language you want to use for your Live Template.
Wen creating you new code snippet you can choose the abbreviation you want to use, the language it can be applied to and the code you want to use in the snippet.
echo __FILE__; echo '<pre>'; print_r($var$); echo '</pre>'; exit;
The above code is a Live Template I use to quickly print_r() variables, as you can see in the code there is a $var$, this is a placeholder for the cursor to focus here once the live template is added to the code.
If you use Github Gists to store your code snippets then you can create new Gists directly in the IDE. All you have to do is highlight the code you want to store, right click and select Create Gist, this will then allow you to enter a description for the Gist and connect to Github to store the code snippet.
Online Documentation Shortcut
If you find yourself looking up the documentation a lot for different PHP functions on PHP.net, then PhpStorm provides you with a quick shortcut to the documentation directly in the IDE. All you have to do is place your cursor on a PHP function and press shift + F1, it will then open a new browser window directly on the page for the function on PHP.net.
Multiple Language Support
PhpStorm doesn't only support the PHP language but most languages that you will need in your website development, including:
- CSS: coding assistance and compilation for LESS; basic support of SASS 3.
- PHP up to version 5.4.0
Built In Version Control
PhpStorm has inbuilt GUI support for Version Control, allowing you to do everything you would with version control directly in the IDE. Making it really easy to make changes to your project, press ctrl + k to commit all these changes into the repository.
It also makes it very easy to make pulls on the repository by pressing ctrl + t will update your code, so you should get into the habit of opening a new project and pressing ctrl + t to get the latest version of the code.
Every new file you create on project is automatically added to the git repository so you don't have to worry about it just code and commit everything when you've done.
After you have committed your changes there is an option to push these changes to repository so you can do everything directly in the IDE.
There is inbuilt support for PHP Unit Testing, allowing you to write unit tests quickly and running them directly in the IDE, there even code coverage reports within the IDE.
To enable PHP unit within PhpStorm there is a good tutorial on their support pages.
To create your tests based on a class is very easy, just right click on a class -> select new -> PHPUnit -> MyClassTest.
PhpStorm was built up by it's plugins, just like other IDEs like sublime you can find a plugin to do almost anything you would ever want. Plugins are available to download for free, from the plugin menu under the settings area.
Some of the most popular plugins allow you to extend the IDE to support PHP frameworks such as Symfony2. If you are used to the style and keyboard shortcuts of Vim then there is a plugin to allow you to use these commands. If you host your repository on bitbucket there is a plugin to integrate with bitbucket to checkout your existing files or share projects directly in the IDE.
There are loads of plugins to choose from when you first install PhpStorm you should have a look at the plugin repository and see if there are any plugins that can help speed up your development.
From PhpStorm 8 it now comes with full support for WordPress this means that the code completion is now integrated with WordPress code, making development so much quicker.
With WordPress support you can setup a development environment configuration for your WordPress plugins, so you can have your plugins in their own PhpStorm project and configure an external library of WordPress so it understands what hooks and filters the plugin will have access to.
There is now code completion on hooks and filters, which means you start creating a add_filter() and press ctrl + space to bring up the suggested filters built into WordPress.
Jumping to callback functions is a new feature with WordPress support, with normal PHP you can jump into a function by holding ctrl and clicking on the function in the IDE. Callback functions are not functions but strings for the name of the function, so before PhpStorm 8 it didn't understand this was a function name and treated it as a string. You can now hold down ctrl and click on the callback function string and PhpStorm will jump to this function declaration.
In the ever changing world of web development it is very important that your IDE can keep up with the changes and constantly be updated with new features helping you develop more efficiently.
This is the main reason why I have moved away from Sublime Text and on to PhpStorm. Sublime Text 2 has not been updated since 8 July 2013, at the time of writing that is almost a whole year. A lot can change in the web over a year and therefore the IDE can not keep up. Sublime Text 3 has been in development for a while and comes with some great features but development on this is slow with the last release being on 17 December 2013 and the one before that on 27 June 2013, 6 months difference between the releases of bug fixes, enhancements and new features.
PhpStorm stable build is currently in version 7.1.3 with version 8 in beta at the moment. They also have an early access program where the build is released with an update every couple of weeks.
It is this active development which pushes PhpStorm above it's rivals.
You can download PhpStorm from the JetBrains website.
It is a paid for software starts at £21 for a academy licence going up to £145 for a commercial licence.
There are so many more features available on PhpStorm that I couldn't fit into this article if you would like to try it yourself the offer a 30 day free trial so you can give it a try before you buy it.
Learn how to code with Treehouse
- Learn projects with access to 1000+ videos
- Practice live with our Code Challenge Engine
- Get help in our members-only forums
Join the weekly newsletter
Sign up for our newsletter. You'll be updated on new tutorials as they come available.
Subscribe today and get a 50% discount code to Paulund