The variable you used does not exist because the error is called through standard_error(), and therefore, the variable is out-of-scope. The global keyword is used to bring a variable into scope, and does not work the way you think it does.
Ok, so basically I hit that hurdle because of the specific situation, while I should have no such problems in other templates, correct?