Relationship between phpfalse and 0

Source: Internet
Author: User
False0, false! 0. problem: the php document shows the statement socket_create () failed to create returnfalse, but why is this sentence correct {code ...} creation error. $ resource should be false. An exception is thrown. The problem is false & amp; lt; 0... false = 0, false! = 0,

Problem:

In the php document, socket_create () fails to be created. return false

But why is this sentence correct?

if (($resource = socket_create(....)) < 0 ){    throw new Exception("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");}

Creation error. $ resource should be false. An exception is thrown. The problem is: false <0 is true. why?

I am a Tom. I want to ask if I want to understand it.

Reply content:

False = 0, false! = 0,

Problem:

In the php document, socket_create () fails to be created. return false

But why is this sentence correct?

if (($resource = socket_create(....)) < 0 ){    throw new Exception("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");}

Creation error. $ resource should be false. An exception is thrown. The problem is: false <0 is true. why?

I am a Tom. I want to ask if I want to understand it.

0 and false are incomplete. Obviously, 0 is of the int type, and false is of the Boolean type.
0 = false // This condition is true and the value is equal
0 = false // This is not true, the type and value are equal, only true

There should be a problem with this writing: I tested

if (($resource = socket_create('1', SOCK_STREAM, SOL_TCP)) < 0) {    throw new Exception("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");}

Not included in the if statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.