An Oracle blog about NetBeans for PHP

Improve Your Code With New Hints

Hi all! After few weeks of inactivity we are here again and we want to show you some new hints which will try to improve your code in NetBeans 7.4 (at least we hope so ;-). So here they are:

Too Many Lines

So what do you think that it does? Yes, exactly :-) It checks the number of lines of class, interface, trait and method (function) declarations. If the number is exceeded, than IDE warns you. So your elements will be more readable and pretty thin :-)

Do you think that the default value is too strict? Don't worry, you can simply adjust it ;-)


Everyone knows superglobals, but not everyone knows that superglobal arrays shouldn't be accessed directly. Never ever trust to user inputs. Every user input should be somehow filtered/validated. And that's why this hint was created :-)


As you certainly know, one can use conditional statements and control structures without curly braces (if block doesn't contain more than one statement). But it makes code less readable, so we suggest you to use braces everytime. This hint works for Do-While, While, For and Foreach loops and for If-Else-ElseIf statements.

Empty Statement

Empty statement is just an empty statement so why to pollute your code by stuff which does nothing?

Error Control Operator Misused

Error control operator is pure evil (we talk about an "at" sign). It hides much more errors than you think. So don't use it. But we allow to use it in some special cases like fopen() and such.

Nested Blocks in Functions

Just another hint which tries to make your code more readable. Too many nested blocks make your code ugly and it also tends to violate single responsibility principle. So it tries to check the depth of your blocks and warns you if it seems suspicious.

And you can set your custom depth number of course ;-)

Parent Constructor Call

Constructor of parent class should be called if exists. It ensures the right initialization of instantiated object. So if you override parent constructor we try to check whether you should call parent constructor or not.

Unnecessary Closing Delimiter

Using PHP closing delimiter at the end of file is unnecessary when there is no text after it. It is just a cause of Headers already sent error and such. So if it finds such an unnecessary delimiter, IDE will warn you.

Unreachable Statement

What are unreachable statements? E.g. statements after return statement. Just snippets which will never be executed. They just pollute your code. Hint tries to detect them and warn you.

Please, don't forget, that all hints are just our suggestions. If you don't want, you don't have to use them. You can simply disable every hint which you don't like in: Tools -> Options -> Editor -> Hints -> PHP. Just uncheck it in the list.

And that's all for today and as usual, please test it and if you find something strange, don't hesitate to file a new issue (product php, component Editor). Thanks.

Join the discussion

Comments ( 25 )
  • Fernando Basso Tuesday, August 13, 2013

    I didn't get the closing ?> delimiter. Does it cause a "headers already sent" error?

  • guest Wednesday, August 14, 2013

    Thank you! It looks to be very practical. Good job.

  • Eli McMakin Wednesday, August 14, 2013

    @Fernando - If you accidentally place a space after the ?> tag, it can cause a "header's already sent error". This is pretty frustrating for new programmers, especially.

    Thank you NB core, for helping make us better coders! Loving the updates.

  • guest Friday, August 16, 2013

    Netbeans is leading the way on static PHP checking!

    Is it too challenging for Netbeans's parser to suppress hints?

    For example, most of the time, I want to be warned about unused variables. Sometimes, I must hack suppressions to please Netbeans. I already filed this feature request:

    foreach ($myArray as $unused => $value) { //would be nice to suppress $unused

    echo $value;


    unset($unused); //sugar to suppress Netbeans hint

    $neverUsed = "This has a real warning that can be fixed";

    Netbeans Java has @suppress, and PhpCodesniffer can suppress blocks

  • Ondrej Brejla Friday, August 16, 2013

    guest: it works properly it 7.4.

  • guest Tuesday, August 20, 2013

    I think the "Superglobals" hint should also warn about using $_REQUEST. :)

  • Ondrej Brejla Tuesday, August 20, 2013

    It warns in the dev build ;)

  • chris Tuesday, August 20, 2013

    Plz make a setting for the psr guidelines to it will be really helpfull, and an autoformat to if can be :)

  • Ondrej Brejla Tuesday, August 20, 2013

    I prepare some code hints for PSR-0 and PSR-1 for next NB version.

  • guest Wednesday, August 21, 2013

    I think this is pretty good information which you shared with us. I always follow your blog for good stuff which I think the good decision of mine. :)

  • Bruce Ingalls Wednesday, August 21, 2013

    Ondrej: Netbeans has 2 Codesniffer plugins. PHP_Codesniffer supports PSR-0, PSR-1 and more.

  • Ondrej Brejla Wednesday, August 21, 2013

    I really know that ;) But those are external CLI tools which have to be executed somehow, I talk about native Hints support.

  • Bruce Ingalls Wednesday, August 21, 2013

    For other readers, who have not used the Netbeans CodeSniffer plugin, it does require you to call `pear install php_Codesniffer`, just as Netbeans requires you to install php, and other php tools.

    The codesniffer plugin does have a native feel inside Netbeans, just like all the php tools in the options menu. However, like php itself, Codesniffer also runs as a CLI program.

    Netbeans is missing a PSR-? code formatting style, which can be saved into XML, and a good place to start. This also means that every time you automatically re-indent your code, you also must fix your code afterwards, to make it PSR compliant.

    I recommend everyone use the Codesniffer plugin (for now), available at http://plugins.netbeans.org/plugin/40282/phpmd-php-codesniffer-plugin

  • Ondrej Brejla Wednesday, August 21, 2013

    And just one note from me, CodeSniffer and Mess Detector tools will have a native integration in NB 7.4 as well ;) But you will have to install them too, of course ;)

  • chris Wednesday, August 21, 2013

    That will be great :) will there also be an psr format option? Currently it's not really possible to set this up correctly in netbeans.

  • Ondrej Brejla Wednesday, August 21, 2013

    Not sure if I'll make it in a time to 8.0 but I have it in my todo list. It's a lot of work.

  • lordnelson Thursday, September 5, 2013

    It would be cool if CodeSniffer/MD which is new in 7.4 beta could be added to the "Hints" feature so that checks are made on-the-fly.

    I have opened a bug with that request:


    Please support my request :)

  • guest Thursday, September 5, 2013

    I could not find a way, to disable the "multiple assignment" hint.

    Sometimes it helps, but more often than not, I wish to ignore warnings, for code, like:

    $stmt = $db->prepare('...');


    $stmt = null; //another assignment; mark for garbage collection

    I realize that alternative syntax sugar exists, such as unset(), or creating a null-setting function (not necessarily improving code).

  • Ondrej Brejla Thursday, September 5, 2013

    guest: Hint is called "Immutable variables"

  • Sherif Sabry Friday, September 6, 2013

    Is there a way to know which projects are currently being worked on by the Netbeans team?

    For example I want to know what features are currently being developed and the road map for the pending features if that's possible.

  • headless_monkeyman Sunday, September 22, 2013

    I'd like to put up my hand and ask for Fixer to go with sniffer and MD. If you have ever had to deal with something really big and horribly written, like say WordPress, you will want to have Fixer to whip the files you decide to work on into shape before you start. Otherwise there will be so many sniffer finds on the page you will hardly be able to read it. And of course it is nice to work with clean, grown up code instead of the armature hour stuff that is in the plugins and templates.

    I know it can't be hard to integrate because I have a plugin handling it in Sublime-Text right now. For those who are not familiar, it is kind of the PHP lovechild of HTML Tidy and Rebase. Just be careful with it. Doc and Sniffer will go out and find your code smells, and Fixer will go take care of the fact your code smells, not the WHY it smells. It is only designed so that people who work in shops that have very tight coding style guidelines can get their stuff checked into git.

    Like I said, great for PHP in WordPress projects. It will fix the 100 ugly things wrong with the code in somebody's functions.php and leave the half dozen really broken things exposed for fixing.


  • guest Friday, February 21, 2014

    Thanks for these hints, I generally find them helpful.

    Just a small criticism on a couple of them where I think more careful use of English would be appropriate:-

    It says here 'Please, don't forget, that all hints are just our suggestions'. If this is true then it is not good English to use words in the Hints like "Must", "Allowed" or "Do not", which imply that the code won't work: ("If-Else Statements Must Use Braces", "Method Length Is 11 Lines (10 allowed)", "Do Not Access Superglobals..."). This is very confusing. Better English would be "Should", "Recommended", "Should not", or "Preferred", "Suggested", etc.

    Thanks again, and keep up the good work!

  • guest Tuesday, April 1, 2014

    It's rather unhelpful to flag references to dollar_SERVER as requiring filtering. Many of the fields provided do not ever need filtering.

  • guest Tuesday, April 1, 2014

    Error suppression is not always evil. Sometimes it's perfectly reasonable, especially when applied to a simple variable. The only error that can arise through referring to a simple variable is that it is unset, so preceding it with the at sign recognises that there are good reasons why the variable may not be set and that null is acceptable. For example, suppose a loop that conditionally sets array elements, but may not always set any element, resulting in the array being unset, and assume the processing is in a method that returns the array. This is neatly achieved by return (array) @$resultarray; and gives the desirable degenerate case of an empty array.

  • guest Sunday, April 20, 2014

    I'd like to second the request for a simple ability to suppress a hint. That would be far more useful than questionable hints such as line counts (sometimes, it just does make sense to have a lot of lines in one place, and I can see by looking how large a class/method is). The example given above is rather artificial, so here is another. Suppose an abstract class that wants to allow subclasses to do extra processing when a particular situation arises. The abstract class has a method

    protected function special ($foo) {}

    which the subclasses can override. It is called by method(s) in the abstract class. If a subclass does not want to process the special situation, it doesn't override the method. The abstract class doesn't want to use an abstract method, because then all the subclasses would be forced to implement the method, even if empty, adding unnecessary clutter. But the method in the abstract class generates a hint ($foo is unused) that is liable to hide genuinely useful hints. And I really don't want to write $foo = $foo; just to make Netbeans happy - that's surely not the way to good coding.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.