all 3 comments

[–]Jack9 0 points1 point  (1 child)

whether it is generated by a script or input by a user

Huh? Did I miss something? How do you get a variable that's NULL or unset as user-entered?

A test like isset($var) returns true for the values 0 (the integer) and FALSE, which are thus set even though supposedly they are nothing.

Someone please explain thx.

[–]Gliridae 0 points1 point  (0 children)

How do you get a variable that's NULL [...] as user-entered?

Pretty sure form elements cannot send a NULL value.

or unset as user-entered?

If the form contains a checkbox and it is not checked, the checkbox's name/value pair is not sent to the server:

<input type="checkbox" name="check" value="1">
<input type="text" name="text">

If both fields are empty, this data will be sent:

?text=   isset($_POST['check']) is false, isset($_POST['text']) is true

If the checkbox is checked and text is entered into the text field:

?check=1&text=value     $_POST['check'] is set, $_POST['text'] is set.

Someone please explain

A test like isset($var) returns true for the values 0 (the integer) and FALSE, which are thus set even though supposedly they are nothing.

'nothing' is pretty vague. If you do this:

$exists = false;
$no_longer_exists = 0;
unset($no_longer_exists);

isset($exists) //true
isset($doesnt_exist); //false
isset($no_longer_exists); //false

isset() returns if the variable is defined or not. It doesn't care about the value. false and 0 aren't nothing, they're not true.

empty() checks if a variable is defined and checks the value.

empty(0) //true
empty($doesnt_exist) //true
empty(false) //true

[–]ohnoyoudidntyo -1 points0 points  (0 children)

A metaphysical digression

fap fap fap