Home >Backend Development >PHP Tutorial >The relationship between php false and 0

The relationship between php false and 0

WBOY
WBOYOriginal
2016-07-06 13:53:301484browse

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.

Reply content:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn