NetBeans71andPhpStorm3

(Difference between revisions)
(Go To Class)
Line 16: Line 16:
There is an option to navigate to PHP Class which is missing in NetBeans. When you have one class per file (with the same name) you can use Go To File in NetBeans but when you have more classes in one file, Go To File doesn’t help you.
There is an option to navigate to PHP Class which is missing in NetBeans. When you have one class per file (with the same name) you can use Go To File in NetBeans but when you have more classes in one file, Go To File doesn’t help you.
 +
 +
'''TMYSIK''' NetBeans has Go To Type (CTRL + o) as well - or am I missing something?
=== Code completion in Find dialog ===
=== Code completion in Find dialog ===

Revision as of 09:30, 5 January 2012

Author: Lada Riha (vriha@netbeans.org)

Following text is supposed to point out features of PhpStorm that could be useful in NetBeans. Its purpose is not to find “best PHP IDE” but to suggest what could be implemented in NetBeans in future. Just because this text contains functionality implemented by PhpStorm and not by NetBeans it doesn’t mean that NetBeans are worst. I simply did not include information about what is better in NetBeans (and yes, there is a lot of thing :)

I did not include everything I've found, but only the in my opinion most interesting and useful functionality. The most important and most wanted in NetBeans would be probably features mentioned in section Refactoring. Ability to inspect code for potential problems, rename php class file together with class renaming or find duplicates are really useful and help user to better/easier reorganize code.

Contents

Editor

Customizing code styles and font styles and colors

PhpStorm and NetBeans both offer a lot of options to customize code styles. One has more detailed settings of that, the other one of something else so it’s hard to tell which is better. However PhpStorm offers also settings for PhpDoc which is missing in NetBeans. Also PhpStorm let user to define some settings for other web related languages (HTML, CSS, JS...).

Configuration of font styles and colors is way better in NetBeans. For example in PhpStorm you can’t change color setting without creating new custom color scheme. Also font settings are more detailed in NetBeans.

Go To Class

There is an option to navigate to PHP Class which is missing in NetBeans. When you have one class per file (with the same name) you can use Go To File in NetBeans but when you have more classes in one file, Go To File doesn’t help you.

TMYSIK NetBeans has Go To Type (CTRL + o) as well - or am I missing something?

Code completion in Find dialog

File:NBPHPS_Findcc.png

PhpStorm offers code completion in Find dialog. It works in all file formats and makes finding a bit more faster.

Show applied styles for tag

File:NBPHPS_AppliedStyles.png

Right click on some HTML tag and press ‘Show applied styles for tag’. Window with all applied css properties will be shown. It also works in Smarty tpl file in which relative addresses for css styles (used in “<link rel=”stylesheet”...”) are not the same as they are in generated php file. This feature is in some way similiar to CSS Preview in NetBeans but instead of showing the styled element, it lists all its style properties.

Autocorrection of PhpDoc

File:NBPHPS_Phpdoc.png

If you change method declaration so the PhpDoc doesn’t correspond anymore, it is underlined and a hint shows explanation. If you click on the bulb icon, you can automatically update PhpDoc.

Formatting of unused variable

File:NBPHPS_Unused.png

All unused variables are gray by default in PhpStorm. Personally, I like it more then underscoring in NetBeans.

Also there is a nice feature that tracks unused values of variables. Look at the picture below you can see that $foo is overwritten immediately and PhpStorm shows it as unused variable (value) and shows hints with explanation.


File management

Name of copied file

If you copy some file in PhpStorm and press Ctrl+V to paste it, you are asked to specify new name. I think this is more useful than NetBeans way when the new file is automatically renamed to “name_1”. On the other hand, in the rename dialog in PhpStorm there is by default name of the original file, so you have to manually change it. I guess ideal way is to combine these approaches, after pasting file user could be asked to specify new name but the “name_1” will be prefilled so he could simple confirm it.

Refactoring

Inspect code

File:NBPHPS_Inspect.png

I’ve found this feature quite useful. It inspects code (php, html, js, css...) in selected files/project and looks for potential errors like empty tags, usage of deprecated methods, incorrect php doc, spelling problems and so on. For some errors it offers quick fixes or excluding them from result. Problems can be grouped by severity, directory etc. You can also export results to html or xml file. Of course there is option to select what should be find with which severity so you can adjust inspections in global scope or per project.

Extract Method

Extract Method action allows to replace selected piece of code with method call. If you select some code and invoke this action, new method will be defined (you can select properties such as parameters, visibility and name) and instead of the selected code there will be single line method call (and of course this method will contain the selected code).

There are also actions like Introduce variable (see blog here) but I don’t think they can really save some time.

Refactor Rename

Both IDE support refactor rename on php classes. I can’t figure out how to force PhpStorm to rename also occurrences of the class name in other files. This handles NetBeans way better. However PhpStorm has a nice feature to rename containing file. So if your php file contains only this one class, you can rename the file itself during the rename refactor action. This is useful if you are using autoloaders that relies on file name.

Duplicates

File:NBPHPS_Dupl.png

PhpStorm allows to find duplicate parts of code. You can specify which language (file format) should be inspected (PHP, HTML, JavaScript...). For each format there are some options to narrow down the inspections (for example for PHP you can specify minimum number of lines of code that could be marked as duplicate). There is also option to inspect only specified files or the whole project.


Other

Show recent changes

File:NBPHPS_Recent.png

Using keyboard shortcut Shift+Alt+C you can easily review all recent changes you’ve made. You can also select some listed file and review changes the same way as if you use versioning system. It’s not a killer feature but it can help you to get in the picture if you haven’t seen your project for some time.

Compare with clipboard

File:NBPHPS_Clipboard.png

This feature allow you to compare selected code with content of your clipboard. The result is displayed in the same way as if you use some versioning system and sometimes it may be pretty handy (not only for php code but in general for all languages).


Local history for directories

This basically only lists all changes in all files in directory, but it’s faster way to track changes in directory than checking every single file.

Diagrams

File:NBPHPS_Uml.png

PhpStorm can generate sort of UML diagrams from given classes so it is easier to understand architecture of your project. You can show class’ methods and variables and do some basic refactoring from the diagram (i.e. renaming). Diagrams can be exported to various formats (png, jpg...) or printed. This is also useful for making documentation.

Show Structure

File:NBPHPS_Structure.png

PhpStorm equivalent of NetBeans’ Navigater offers more filter options (show contants, show fields, includes, show inherited etc.) while in NetBeans there are only 3 options to use and some of this functionality is in Php Type Hierarchy. In PhpStorm it also tries to deduct type of variable.

Open URL

This is probably not going to be used a lot but sometimes it can be useful. PhpStorm can open file from given URL.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo