View Full Version : Quick Question

03-18-2007, 07:33 PM
Whats the difference with these two variable assignments in PHP



Mainly I'm wondering what the @ does.



03-18-2007, 08:10 PM
It suppresses the output of error messages. In this case, if the get variable does not exist.

There are very few cases where the @ should be used. It typically gets used to suppress a nuisance error message instead of having proper conditional logic.

Inputs to programs always need to be tested and validated and an appropriate action needs to be taken depending on what was entered. Code that does not check its input data is the code you see posted in a Forum like this with a "why does this code not work?" question.

For the case of a variable from a form/url parameter, you should do something like the following -

// the get variable is set
} else {
// the get variable is not set
// set a default value
$category= 0;
// and/or generate some error reporting and feed back as to what is wrong with the data -
echo "You did not enter a value for category";

03-18-2007, 09:03 PM
Thankyou for your response

Good to know that.