Jump to content

Difference btw these 2


quelle

Recommended Posts

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'];

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.

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.