### Eclipse Workspace Patch 1.0
#P moodle
Index: lib/accesslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v
retrieving revision 1.140
diff -u -r1.140 accesslib.php
--- lib/accesslib.php	26 Sep 2006 13:31:57 -0000	1.140
+++ lib/accesslib.php	27 Sep 2006 07:36:20 -0000
@@ -1156,16 +1156,24 @@
 function get_context_instance($contextlevel=NULL, $instance=SITEID) {
 
     global $context_cache, $context_cache_id, $CONTEXT;
+    static $allowed_contexts = array(CONTEXT_SYSTEM, CONTEXT_PERSONAL, CONTEXT_USER, CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_GROUP, CONTEXT_MODULE, CONTEXT_BLOCK);
 
 /// If no level is supplied then return the current global context if there is one
     if (empty($contextlevel)) {
         if (empty($CONTEXT)) {
-            debugging("Error: get_context_instance() called without a context");
+            //fatal error, code must be fixed
+            error("Error: get_context_instance() called without a context");
         } else {
             return $CONTEXT;
         }
     }
 
+/// check allowed context levels
+    if (!in_array($contextlevel, $allowed_contexts)) {
+        // fatal error, code must be fixed - probably typo or switched parameters 
+        error('Error: get_context_instance() called with incorrect context level "'.s($contextlevel).'"');
+    }
+
 /// Check the cache
     if (isset($context_cache[$contextlevel][$instance])) {  // Already cached
         return $context_cache[$contextlevel][$instance];
