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.