Home >Backend Development >PHP Tutorial >The relationship between php false and 0
false == 0, false !== 0,
Question:
The PHP documentation states that socket_create() fails to create and returns false
But why is this sentence correct
<code>if (($resource = socket_create(....)) < 0 ){ throw new Exception("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); }</code>
Creation error, $resource should be false, and an exception was thrown. The problem is that false<0 is established. Why?
I am a novice, so I want to ask if I don’t understand.
false == 0, false !== 0,
Question:
The PHP documentation states that socket_create() fails to create and returns false
But why is this sentence correct
<code>if (($resource = socket_create(....)) < 0 ){ throw new Exception("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); }</code>
Creation error, $resource should be false, and an exception was thrown. The problem is that false<0 is established. Why?
I am a novice, so I want to ask if I don’t understand.
0 and false are not congruent. It is obvious that 0 is of int type and false is of Boolean type.
0 == false //This condition is true and the values are equal.
0 === false //This is not true. The types are equal to This is true only if the values are equal
There should be something wrong with this way of writing: I just tested one
<code>if (($resource = socket_create('1', SOCK_STREAM, SOL_TCP)) < 0) { throw new Exception("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); } </code>
I found it was not included in the if statement