Identical Comparison Hint

Hi everybody! Today we would like to introduce you some of our new hints. This one is called Identical Comparisons and checks whether you use more strict identical comparison instead of simple equal comparison. If not it suggests you to change it to identical one.

If you don't know what is the difference between identical and equal comparisons, you can read it in official PHP manual.

And because we know, that sometimes there is a use case when you should use just equal comparison, this hint is row sensitive. It means that well known hint bulb will appear only if you are on the row with comparison. So no yellow warning triangle will scream on you ;) This hint just wants to help you :)

But there is just another advantage of this hint. It can change your "==" sign to "===" as you certainly expected, but it can detect the type of the right hand side variable and make a type cast for you too!

Identical Comparisons

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.

Comments:

Nice idea! I always try to teach our Juniors that even if you don't HAVE to use strict typing, it doesn't hurt if you do so where needed.

"Equal" is good when comparing:
- (1 == 1.0) is TRUE (you want that)
- (1 === 1.0) is FALSE (just not that).

BUT use "identical" comparison for:
- ("false" == TRUE) is TRUE (not the equation you were looking for)
- ("false" === TRUE) is FALSE (yes, that's it!).

Posted by Tom on January 26, 2012 at 10:32 PM CET #

is it something new or what? in what age you guys are living in... that == and this === been there for ages. wake up. dont push them in people's brain like they didnt exist before..

Posted by guest on January 31, 2012 at 12:17 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today