Skip to main content

Posts

Showing posts from March, 2017

Debate: Identical Operator vs. Equality

Sometimes I call this "loose equality" (==) and "strong equality" (===) but regardless of what you call it, the inclusion of loose equality is one of the most maligned features of PHP.  Traditional programmers say using loose equality operators is a terrible practice - and for the most part, they are right.  In general, when you are checking if two variables are equal, you really mean to check if they are identical.  In other words, a string should not equate with an integer, even though they may *look* the same to a human. However, what traditional programmers tend to miss is that one of PHP's strengths is the ability to be portable.  Strong equality is one of the things that breaks portability.  Therefore, assuming you are validating input and working in the realm of positive integers (non-zero), loose equality is the only way to go! An example of this issue came up for me recently as I was moving my code from MySQL to Azure/MS-SQL in Laravel 5.3.  For wha