Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added assert_var_set() - part of trying to deprecate required_variabl…

…e (which

is used in two different ways)
  • Loading branch information...
commit f24e18ee85778ea0be4708c657add52ed4051e1d 1 parent b20337b
thepurpleblob authored
Showing with 13 additions and 1 deletion.
  1. +13 −1 lib/moodlelib.php
14 lib/moodlelib.php
View
@@ -352,6 +352,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
*
* If $var is undefined throw an error, otherwise return $var.
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.