This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Created attachment 137409 [details] A example case when the warning shows In a PHP functions, NB will notice that an if statement with only one line to do need braces, like: if(empty($password)) die(); This will be a yellow line under the second line, and saying "if-else Statements Must Use Braces". But if you change it to: if(empty($password)) { die(); } There's no warning message. This error occurs on NB 7.4 Beta (not tested on 7.3), but it works fine on NB 7.2.1.
And it's ok, because you change it to a proper format...if statement with braces, so hint disappeared :) It's a new hint and you can switch it off in options -> editor -> hints -> php.
(In reply to comment #1) > And it's ok, because you change it to a proper format...if statement with > braces, so hint disappeared :) It's a new hint and you can switch it off in > options -> editor -> hints -> php. Ops, now I see. But I think the former one is also a proper format too. Check out the PHP Manual (http://www.php.net/manual/en/control-structures.if.php) and it use: <?php if ($a > $b) echo "a is bigger than b"; ?> as an example.
Yes, you can use it...but we suggest to don't use this type of conditions. It's more readable with brackets. It's the same behavior as is in java editor...
(In reply to Ondrej Brejla from comment #3) > Yes, you can use it...but we suggest to don't use this type of conditions. > It's more readable with brackets. It's the same behavior as is in java > editor... Even though I agree it is best practice to always use braces (for many reasons I'm don't want to focus on arguing) I REALLY think it should be rephrased to "if-else Statements Should Use Braces" My students where really confused about the phrasing of this warning, when they have seen code (not by me) without braces and they dont understand how it can work if if-else MUST (mandatorily, obligatorily, by definition) use braces. Must is must, should is should. Lets user proper words :)
I come back to comment that actually I'm back to add that a work mate pointed out that some platforms, like Prestashop, have in their coding standard the OBLIGATION of NOT using curly braces in one-statement blocks (you can read one of many discussion about the topic here: http://forge.prestashop.com/browse/PSCFV-2044 I don't agree with this so-called "standard", of course, but you all will agree that Prestashop is not a small thing to just ignore, so I think this is another reason to take into account towards de "Should" instead of "Must", because "must" is an obligation, if you do what you must do, they won't accept your code. And they must accept my code! Don't put me in that situation! (xDD) Now seriously, it's best practice. A really good one, but not an obligation, so even if it's marked as warning and not error, I really think you should rephrase that :)
This bug still exists in 8.2 "Enforcing" this warning to push people to use braces ain't a good practice due many reasons. And I believe there should be an options for "accept one-liners or not" as per project basis.