Skip to content

Commit

Permalink
Added isset_param() convenience function to test if a param is set.
Browse files Browse the repository at this point in the history
To get the nasty activity in one place and to improve code readability.
  • Loading branch information
thepurpleblob committed Jun 10, 2005
1 parent 8ee1b0a commit 7a53027
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lib/moodlelib.php
Expand Up @@ -171,6 +171,21 @@ function optional_param($varname, $default=NULL, $options=PARAM_CLEAN) {
return clean_param($param, $options);
}

/**
* Convenience function to test if a parameter is set
* @param string $varname name of the parameter
* @return boolean true if set otherwise false
*/
function isset_param($varname) {
if (isset($_GET[$varname])) {
return true;
}
if (isset($_POST[$varname])) {
return true;
}
return false;
}

/**
* Used by {@link optional_param()} and {@link required_param()} to
* clean the variables and/or cast to specific types, based on
Expand Down Expand Up @@ -415,13 +430,29 @@ function require_variable($var) {
function optional_variable(&$var, $default=0) {
global $CFG;
if (!empty($CFG->disableglobalshack)) {
error( 'The optional_variable() function is deprecated.' );
error( "The optional_variable() function is deprecated ($var, $default)." );
}
if (! isset($var)) {
$var = $default;
}
}


/**
* If a variable is empty set it to the default
* otherwise leave it alone
* @param mixed $var the variable to test
* @param mixed $default the default value
* @return boolean true if variable has changed
*/
function set_default( &$var, $default ) {
if (empty($var)) {
$var = $default;
return true;
}
return false;
}

/**
* Set a key in global configuration
*
Expand Down

0 comments on commit 7a53027

Please sign in to comment.