[asterisk-users] AEL: how to check if variable is defined

Dave Fullerton dfullertasterisk at shorelinecontainer.com
Mon Dec 29 14:45:52 CST 2008


Philipp Kempgen wrote:
> Philipp Kempgen schrieb:
>> Klaus Darilion schrieb:
>>> I use an "if" condition in extensions.ael to check if a channel variable 
>>> is defined and if defined I add a certain header:
>>>
>>> context toNormaleRufe {
>>>    _X. => {
>>>             if (${NUMBER}) {
>>>                 SIPAddHeader(X-NUMBER: ${NUMBER});
>>>             };
>>>             ...
>>>    };
>>>
>>> This works fine, except NUMBER starts with the + sign.
>>>
>>> I tried using quotes but
>>>     if ("${NUMBER}")
>>> evaluates always true.
>>>
>>> What is the suggested way to solve this?
>> if ("${NUMBER}" != "") {
>>     // ...
>> }
>>
>> That doesn't tell you whether the variable is defined but in
>> most cases (if any) that doesn't matter anyway.
> 
> But I guess it wouldn't hurt to add a DEFINED() function to
> Asterisk.
> 
> if (DEFINED(myvariable)) {
>     // ...
> }
> 

Isn't that what EXISTS() is for?

-Dave



More information about the asterisk-users mailing list