Avatar of nachtmsk
nachtmsk
Flag for United States of America asked on

Php -- what is this code doing

Hi,
I'm working on fixing a Form issue from some old code I inherited.
Can someone tell me what exactly this code is doing and returning (or should return)?

Thanks
Nacht

function CCGetFromGet($parameter_name, $default_value = "")
{
    global $HTTP_GET_VARS;
    return isset($HTTP_GET_VARS[$parameter_name]) ? CCStrip($HTTP_GET_VARS[$parameter_name]) : $default_value;
}
PHPScripting Languages

Avatar of undefined
Last Comment
nanharbison

8/22/2022 - Mon
nachtmsk

ASKER
I'm particularly curious about the  line that starts   'return isset  ... '
Does a FORM need the data that this line would return in order to be Submitted?

Thanks
SOLUTION
Marco Gasi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Scott Madeira

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
nanharbison

The PHP function isset returns true or false, so I am having trouble with the structure of this statement.. Within the isset parentheses is a true false statement using T/F shorthand called ternary operators. It says, if the parameter has been set, then return that value. If it isn't set, return the default value. So why is it in an isset statement? It should return true either way.
Have you tried echoing out what is returned?
It seems like this function is choosing a value for one element of the form, either the value the person entered or chose, or the form element is filled with the default value.
Someone correct me if I am wrong, maybe I am about to learn something new.
Derokorian

Within the isset parentheses is a true false statement using T/F shorthand called ternary operators.
False, the return on isset is what is used to evaluate the conditional. These 2 stuctures are identical:
return isset($HTTP_GET_VARS[$parameter_name]) ? CCStrip($HTTP_GET_VARS[$parameter_name]) : $default_value;

// Same as
if( isset($HTTP_GET_VARS[$parameter_name]) ) {
   return CCStrip($HTTP_GET_VARS[$parameter_name]);
} else {
   return $default_value;
}

Open in new window


No points please, just trying to clarify.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
nanharbison

Thanks Derokorian.