Q.
On this page:
https://www.tutorialspoint.com/php/php_variable_types.htm
On section "Interpreting other types as Booleans", it says:
"Don't use double as Booleans".
I do not understand this. Why can't you use a double as a boolean ?
Why can't we use the following example ?
EXAMPLE 1:
$int_var = 100.10;
If($int_var != 100.10);
echo "FALSE";
else echo "TRUE";
EXAMPLE 2:
$int_var = 16.5;
If($int_var < 16.5);
echo "You're under age!";
else echo "You're old enough!";
Q2.
On the same page under the same section as above, it says:
"Each of the following variables has the truth value embedded in its name when it is used in a Boolean context.
$true_num = 3 + 0.14159;
$true_str = "Tried and true"
$true_array[49] = "An array element";
$false_array = array();
$false_null = NULL;
$false_num = 999 - 999;
$false_str = ""; "
Now my question ....
I can understand the following is considered TRUE because the value of the number is not zero.
$true_num = 3 + 0.14159;
I can understand the following is considered TRUE because the value of the string is not blank or empty and holds a value.
$true_str = "Tried and true"
Saying all this, I guess white space or the TAB/INDENT is considered as FALSE if some-how there can be "values" set to them one way or the other. But, I guess not.
I can understand the following is considered TRUE because the value of the ARRAY is not zero or blank/empty. Correct ? (I have a little doubt about this one).
$true_array[49] = "An array element";
I can understand the following is considered FALSE because the value of the ARRAY is blank/empty. I guess if the value held "0" then it would be FALSE too. Correct ? Correct me if I'm wrong.
$false_array = array();
My REAL question is this following one. How can that variable be considered FALSE since the NULL holds a NULL ? A negative "-" holds a negative "-". Or a "zero" holding a "zero" is TRUE. Right ? Don't understand this logic.
$false_null = NULL;
Let's face it. Imagine you're a robot who accepts donations. Now, I come along and program you to not accept any donations anymore. No holding money in your pockets anymore. Some guy comes and tries giving you money but you refuse. When I get back, I try seeing if your pockets are empty (NULL) and find it is. Did you live-up to the NULL ? Yes, you did. And so, it is a TRUE NULL. Not FALSE. Right ?
Unless, I'm understanding NULL wrong some-how. I see when we create tables in mysql, we assign whether a column should be NULL or not. I'm guessing, if we assign it not to be NULL then on every input to the table that column must get inputted a value. Else, mysql will spit an error. If it's set to NULL then that means the column can be not filled even though other columns are getting filled in a go. Correct, or have I got my wires crossed some-how ?
I can understand the following is false because the value of the variable would be zero. Right ?
$false_num = 999 - 999;
That page further says on the NULL section:
"A variable that has been assigned NULL has the following properties −
It evaluates to FALSE in a Boolean context.
It returns FALSE when tested with IsSet() function".
I'm having trouble understand "It evaluates to FALSE in a Boolean context" for reasons mentioned just above.
:confused:
Maybe, some examples from you guys can clear this misconception on my part (if any). :D
It returns FALSE when tested with IsSet() function".
Anyone kind enough to show 2 examples of the IsSet() function here where the variable with a NULL value would be considered FALSE ?
:confused:
Thank you for your time and help. :)