So I recently encountered an error with when I had !==, it returns to true. Say for an example, if 4 !== “5” it becomes false on my live server. But If I use just st it works as intended.
Does !== mean that the type should also not match? I mean an Int and a String. Where as for !=, it matters only for the value and it does not care about the type. Am I on the right page?
So what is the difference? Also I should note that !== works perfect on my local development.
Yes that is what I said above. Basically if it was a string and an int, it will be true. But in this case they both are int's. 5 !== 4 is false. But 5 !== "4" is true because the types is not equal to each other.
I think that is a typo in the OP. There is no such thing as a ! followed by 3 = signs in php. You'll get an error, so it couldn't have been working for him.
>>> 5 !=== 4
PHP Parse error: Syntax error, unexpected '=' on line 1
@Snapey 4 !== 5 will return false won’t it? But 4 != 5 will return true. Because of the type difference. 4 is not equal to 5 is correct. But also it is false because int is equal to int. Hope I am making sense here. 4 !== 5. Both are integers. However 4 !== “5” is true. “5” is a string. So they are not equal in anyway.
@jlrdw Yes it was a typo and you are absolutely correct.
So to wrap things up, !== is same as === and != is the equivalent of ==. !== will return true only if the values AND types are different. Where as != will be true if the value is different and does not care about the types.
@Snapey My server does not except this. 4 !== 5 returns false because of the type difference. I am on laravel 5.6, PHP 7.2.10. The only difference is that I have my MySQL Native Driver disabled. So if I am taking a value from db and comparing it with some other value like the example above, it returns false. But 4 != 5 returns true.
I think It has to do with MySQLnd (On my server I mean)
In != we check is it "not equal to" example: 2 !=4 .. it will give true. and in !== we check for value as well as type. example: 2 !== 4 .. it will give true. but a !== 2 it will give false as "a" is a string and 2 is an integer.
>>> 4 != '4'
=> false // because they are loosely the same
>>> 4 !== '4'
=> true // because they are not the same type even though they are loosely the same
As @Snapey and everyone else has been saying is that when using strict comparison like === and !== the type and the value are evaluated. It might be easier to thing about === which says both type and value must be equivalent
If it's solved, maybe mark it solved? I still don't know why you mention the sql driver or what you think it has to do with your problem? We're just trying to make sure you're clear because you are mentioning things that don't seem to or shouldn't have anything to do with it.