How to supress a warning in PHP files for Netbeans?

两盒软妹~` 提交于 2019-11-28 09:57:59

问题


I have a PHP file with a line that produces a warning in the NetBeans. How can I force the IDE to ignore that concrete warning? Notice that I don't want to disable this type of warning solution-wide.

Here is a sample line of code:

if ($query = db_query("SELECT column FROM {table} WHERE type='some_value'")) { ... }

Here is a text of produced warning: 'Possible accidental assignment, assignments in conditions should be avoided.'

UPD: Dear colleagues, I know how to correct the code, but notice that I've asked completely other question! I need a way to suppress the warning having the same statement in the if clause.

I 'm not going to use the @ Operator also because it has completely other mission.

UPD2: Below you can see how I suppress the Resharper warning(s) in C#. I want something like that in PHP for NetBeans:

// ReSharper disable PossibleNullReferenceException
_currentPage = restoredStageSurvey._currentPage;
// ReSharper restore PossibleNullReferenceException

回答1:


While you can't just disable one warning (look for bug reports like http://netbeans.org/bugzilla/show_bug.cgi?id=97224), there is a common solution for this problem(if you have "Ignore assigments in sub-statements" turned ON):

if(($x=$y)) {}

TLDR: Double brackets = Ignore this type of warning.




回答2:


Maybe there is a way to suppress that warning in Netbeans, I don't know.

However, you could also just heed the warning and change your code - it won't do it any harm. The issue Netbeans complains about isn't anything terrible, but it is good style to separate query and condition like so:

$query = db_query("SELECT column FROM {table} WHERE type='some_value'");

if ($query) 
 { ... }
else 
 { // die and report error }



回答3:


You can control the hints/warnings that NetBeans provides through Tools > Options > Editor > Hints. You can turn off this specific hint by choosing Language: PHP and unselecting the "Possible accidental assignment, assignments in conditions should be avoided" checkbox.

You should however heed the advise of the other answers and reconsider this style.



来源:https://stackoverflow.com/questions/8357589/how-to-supress-a-warning-in-php-files-for-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!