Asterisk: Dropping calls with an "ast_yyerror"

In an Asterisk $[] expression, undefined variables do not return an implicit empty string or zero. They expand as "nothing" prior to evaluation of the expression, so after the variable is expanded (to nothing), it isn't visible to the expression parser. This causes the error already noted by Pablo Alsina:

GotoIf("IAX2/AtlantaTeliax-10086", "?CLOSED,1")

There are two ways to avoid this:

  1. Always give your variables reasonable defaults before you use them (as Pablo suggested).
  2. In any $[] expression, enclose your variables and literals with double-quotes. This will cause an undefined variable to be handled as an empty string, which can still be used for comparison purposes.

Personally, I try to do both. For example:

exten => START,n,Set(FORCE_CLOSED=FALSE)
exten => START,n,GotoIf($["${FORCE_CLOSED}"="TRUE"]?CLOSED,1)

Note the double-quotes around ${FORCE_CLOSED} and the comparison value. Even if the variable is undefined, the expression will have "" (an empty string) to compare against "TRUE".

Really, you can use any character you like, because it will just be tacked onto the variable expansion. It just gives you a literal value that is guaranteed to be there in case the variable is undefined. I like quotes because it makes the code resemble other programming languages. You could just as easily use something like $[x${FORCE_CLOSED}=xTRUE], which is commonly seen in Bourne shell scripting. The end result is the same.