Let me start by saying I know nothing about Joomla or PHP so i might be comparing apples to oranges here but….
I keep seeing JRequest::getVar($var) and $var in some code i’ve been looking at. Can someone explain what the difference between these two is?
According to Joomlas’ documentation getVar , “Fetches and returns a given variable.” If that is the case why would the following code return different results?
echo JRequest::getVar($amount);
echo $amount;
Disclaimer: I don’t know the first thing about Joomla.
Looking at the documentation,
JRequest::getVarfetches values from GET or POST parameters and is supposed to be used likeJRequest::getVar('amount')(note the argument is a string, not a variable).echo $amountandecho JRequest::getVar($amount)are of course nowhere near equivalent, the former means “echo the value of$amount“, the latter “echo the value of a GET or POST variable with the name of the value of$amount.”The second parameter
$defaultis also very useful:Even without the second parameter though, it’ll take care of variable cleaning and (un)escaping where necessary, so it’s a good idea to use this function to read request parameters.