diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 472021171f5..ee3d422588c 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -351,6 +351,19 @@ function confirm_sesskey($sesskey=NULL) { } +/** + * Improved ensure a variable is set + * Issue a (custom) error message if not + * @param mixed $var the variable + * @param string $error optional additional error message + */ +function assert_var_set( $var, $error='' ) { + if (! isset($var)) { + error( "a required variable is not set - $error" ); + } +} + + /** * Ensure that a variable is set * @@ -371,7 +384,6 @@ function require_variable($var) { * Ensure that a variable is set * * If $var is undefined set it (by reference), otherwise return $var. - * This function will soon be made obsolete by {@link optional_param()} * * @param mixed $var the variable which may be unset * @param mixed $default the value to return if $var is unset