When I executed get_defined_constants(), I accidentally discovered that PHP has an internal constant with the name true and the value 1. There are also constants named false and null.
Does PHP treat true as a constant? Shouldn't it be a "value"?
Shouldn’t it be a value with data type boolean?
I tried to execute echo(true), the browser output the character 1, and when I var_dump(true), it output bool(true). Isn’t this an obvious contradiction?
Also, true===1 is not true. true==1 is established.
So I want to know how php handles true false null.
When I executed get_defined_constants(), I accidentally discovered that PHP has an internal constant with the name true and the value 1. There are also constants named false and null.
Does PHP treat true as a constant? Shouldn't it be a "value"?
Shouldn’t it be a value with data type boolean?
I tried to execute echo(true), the browser output the character 1, and when I var_dump(true), it output bool(true). Isn’t this an obvious contradiction?
Also, true===1 is not true. true==1 is established.
So I want to know how php handles true false null.
echo input is a string, so true is type-converted. You can refer here
1 2 3 4 5 |
|
Reference documentation
Crooked building. Tell a C++ story.
Windows API has a data type BOOL
, with a similar definition
1 |
|
Then there are TRUE
and FALSE
macros, the definitions are respectively
1 2 |
|
C++ itself also has a macro NULL
, the definition is
1 |
|
And I suspect that PHP treats true
as a boolean type 1. Just guessing, please feel free to object if I'm wrong.