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 isTRUE
AndFALSE
Macro, 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 istrue
As a boolean type 1. I guess it is incorrect. please feel free to oppose it.