Php has a predefined constant true with an integer of 1. how can this problem be solved?

Source: Internet
Author: User
Tags define null
When executing get_defined_constants (), I found that php has an internal constant named "true" and the value is an integer of 1. it is also known as a constant of "false" and "null. Does php treat true as a constant? Shouldn't it be a "value? It should not be a data type of bo... when executing get_defined_constants (), I found that php has an internal constant named "true" and the value is an integer of 1. it is also known as a constant of "false" and "null.
Does php treat true as a constant? Shouldn't it be a "value?
Shouldn't it be a boolean value?
I tried to execute echo (true), and the browser output character 1, and I var_dump (true), output bool (true). isn't that a clear contradiction?
In addition, true = 1 is not true. True = 1 is true.
So I want to know how php handles true, false, and null.

Reply content:

When executing get_defined_constants (), I found that php has an internal constant named "true" and the value is an integer of 1. it is also known as a constant of "false" and "null.
Does php treat true as a constant? Shouldn't it be a "value?
Shouldn't it be a boolean value?
I tried to execute echo (true), and the browser output character 1, and I var_dump (true), output bool (true). isn't that a clear contradiction?
In addition, true = 1 is not true. True = 1 is true.
So I want to know how php handles true, false, and null.

The echo input is a string, so true has a type conversion. Refer to here

Printing or echoing a FALSE boolean value or a NULL value results in an empty string:(string)TRUE //returns "1"(string)FALSE //returns ""echo TRUE; //prints "1"echo FALSE; //prints nothing!

References

Building. Tell a story about C ++.
Windows API has a data typeBOOL, The definition is similar

typedef int BOOL;

Then there isTRUEAndFALSEMacro, which is defined

#define TRUE 1#define FALSE 0

C ++ has a macro.NULL, The definition is

#define NULL 0

And I suspect that PHP's approach istrueAs a boolean type 1. I guess it is incorrect. please feel free to oppose it.

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.