An Oracle blog about NetBeans for PHP

Ambiguous Comparison Hint

Hi everybody! Today we would like to show you some new hint which will be available in NetBeans 7.3. It's called Ambiguous Comparison hint.

Its name seems to be quite fuzzy, but it describes exactly what the hint does. It tries to check all comparisons whether they are intended. Because sometimes you want to make a simple assignment, but you make a typo and comparison appears. It's really dangerous mistake because then your code doesn't work as expected. Your application can produce buggy results. So here is how it looks like:

Ambiguous Comparison Hint

But sometimes a comparison is really intended. E.g. in return statements when you want to return a boolean, so then the hint works as expected and no warning appears.

Ambiguous Comparison Hint

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 (component php, subcomponent Editor). Thanks.

Join the discussion

Comments ( 6 )
  • guest Wednesday, October 17, 2012

    What are you using for blue bracket near line numbers?

  • Tom Wednesday, October 17, 2012

    That is nice. But could you possibly change the hint text? If I read "ambiguous comparison" a junior developer would not know what you want of him. Plus some people may have problems reading English, so I would suggest to avoid words like "ambiguous" when a more common word can be used to express the same thing.

    How about "Possible accidental comparison found. Check if you wanted to use '=' instead of '=='".

    Always use clear explanations with simple instructions of 1) what is wrong and 2) how the developer can fix it. Otherwise junior developers will just ignore the warnings.

  • Ondrej Brejla Wednesday, October 17, 2012

    guest: it's a new feature of Nb 7.3. It works out of the box.

    Tom: Ok, we can definitely improve it.

  • Eli McMakin Wednesday, October 17, 2012

    Nice feature. NetBeans just keeps getting better and better. I also noticed the CSS improvements in 7.3. Now, the "*" symbol in CSS is not being shown as an error. And vendor prefixes seem to be working, for the most part. Nice job, NetBeans.

  • guest Wednesday, May 8, 2013

    Why it marks this as accidental comparison?

    switch(true) {

    case($a == 0): // here


    case($a == $b): // or here


    case($a != $b)


  • Ondrej Brejla Thursday, May 9, 2013

    Thanks for catching that, I filled a new issue - https://netbeans.org/bugzilla/show_bug.cgi?id=229529

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