PHP has a predefined constant of true, and the value is an integer 1, how is this understood?

Source: Internet
Author: User
Tags define null
When I executed get_defined_constants (), I accidentally found that PHP had an internal constant with the name true, a value of integer 1, and a constant known as false and null.
Does PHP handle true as a constant? Isn't it supposed to be a "value"?
Shouldn't it be a value with a Boolean data type?
I tried to execute Echo (true), the browser output character 1, and I var_dump (true), output bool (true), this is not obviously contradictory?
Moreover, True===1 is also not tenable AH. True==1 is the foundation.
So I want to know exactly how PHP handles true false null.

Reply content:

When I executed get_defined_constants (), I accidentally found that PHP had an internal constant with the name true, a value of integer 1, and a constant known as false and null.
Does PHP handle true as a constant? Isn't it supposed to be a "value"?
Shouldn't it be a value with a Boolean data type?
I tried to execute Echo (true), the browser output character 1, and I var_dump (true), output bool (true), this is not obviously contradictory?
Moreover, True===1 is also not tenable AH. True==1 is the foundation.
So I want to know exactly how PHP handles true false null.

The echo input is a string, so true has the type converted in. You can refer to this

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!

Reference documents

Crooked Building. Tell a story of C + +.
The Windows API has a data type BOOL that defines a similar

typedef int BOOL;

And then there are TRUE and FALSE macros that are defined separately are

#define TRUE 1#define FALSE 0

C + + also has a macro NULL , the definition is

#define NULL 0

And I suspect that PHP's approach is to treat as a true Boolean type of 1. I guess it's wrong. Please 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.