Token identical "==" is used only in PHP? Because?

7

During my studies in C language and Java, I have always come across the sign "=" of assignment and the "==" sign being equality . However, I'm studying PHP now and I came across the sign "===" of identical .

My questions are:

  • Is identical sign used only in PHP? If so, why?
  • If not, which languages have this signal?
  • If C and Java have it, why is it not so well known / taught along with the other signs?
asked by anonymous 27.02.2017 / 16:12

1 answer

11
  

Is the Signal of identical used only in php? If not, which languages have this sign?

No, it's used at least in JavaScript too , perhaps in other languages of dynamic and weak typing .

== compares the values in the best possible effort, if the types of each operand are different the language tries to match them to be able to make the comparison. This may bring unwanted results .

The === considers the type and no coercion is done. If the types are different it is already guaranteeing that the result will be different and the value will only be evaluated if the types are the same.

  

If yes, why?

PHP is a script language, it was meant to "facilitate" quick code creation and the programmer did not have to worry about certain details, so this made sense. Today the language tries to stop being script , but it needs to maintain compatibility, so it gets this kind of schizophrenic thing.

  

If C and Java have it, why is it not so well known / taught along with the other signs?

This is characteristic of weak typing languages where a value can be passed as if it were of another type. Java is not like this.

C even so, but in a slightly different way, you usually do not try to do conversions, it just tries to access and memory roughly. They never found it necessary to have an "identical" operator in C because the philosophy of language is to let them access anyway. But today almost all compilers at least optionally produce warnings when this occurs forcing the programmer to use a cast to indicate that the intent is to use one type as if it were another. >

It is very rare for a language to have static and weak typing, C is so because it is considered a portable Assembly.

Even dynamic typing languages opt for strong typing, such as Python , Moon , Harbor , etc.

    
27.02.2017 / 16:27