Jump to content

Difference btw these 2


quelle

Recommended Posts

isset - Determine if a variable is set and is not NULL.

if - If expression evaluates to TRUE, PHP will execute statement, and if it evaluates to FALSE - it'll ignore it.

 

More detailed explanation in the manual links above.

Link to comment
Share on other sites

the first example will throw an error saying name is undefined if it wasnt found in the $_POST array, that is Null

 

isset is a way of being sure something exists before retreiving its value

 

i usually retreive all my form values like this

 

if (isset($_POST['name'])) $name = $_POST['name'];

Link to comment
Share on other sites

yes you would get the same thing at the end.

 

its a technique to prevent errors in your code with undefined variables.

its down to personal preference, but really its better to catch potential errors than not, even if you know that $_POST is going to be there.

 

you dont have to do it, just like you dont have to do many things in code, but in a professional environment, it would be expected to write code that is covering any possible errors that might be thrown.

 

Link to comment
Share on other sites

if is not a function. It's merely an operator (correct me if I'm using the wrong terms).

isset is a function. It checks if the variable that you are looking for actually exists in memory and returns true if it is, false if it isn't.

empty is a function. It checks if the variable is in memory and if it's not NULL, '' or whatever it will juggle as an empty variable. It returns false if one of those conditions are false.

 

I suggest that you do some reading of these PHP tutorials on W3Schools.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.