isset vs empty vs is_null

后端 未结 14 2153
野的像风
野的像风 2020-11-29 08:34

I\'m trying to write a script that when a user uploads a file and does not enter a name an error is returned. I\'ve tried using is_null, empty, and isset and they all do not

14条回答
  •  Happy的楠姐
    2020-11-29 08:59

    isset() will check if the variable is set, ie

    empty() will check if the variable is empty, ie

    is_null() will check for NULL which is different from empty, because it's set to NULL not an empty string. (NULL might be a confusing concept)

    Since your title is a string, I think you want to be using empty()

    if (!isset($_REQUEST[$name_input_name]) || empty($_REQUEST[$name_input_name])) {
        $file->error = 'Please Enter a Title';
        return false;
    }
    

提交回复
热议问题