[sr-dev] trouble with testing $var

Juha Heinanen jh at tutpro.com
Mon Nov 9 21:58:25 CET 2009


Andrei Pelinescu-Onciul writes:

 > >    $var(tmp) = $(ru{uri.param,alias});
 > >    xlog("L_INFO", "Alias param is <$var(tmp)>\n");
 > >    if ($var(tmp)) {
 > > 	    xlog("L_INFO", "Alias param is <$var(tmp)>\n");
 > > 	    $du = $var(tmp);
 >         ^^^^^^^^
 >         shouldn't it be $du = "sip:" + $var(tmp) ?

andrei,

yes, it should have been like that.  now handle_alias() takes care of
it.

 > > why does the test
 > > 
 > >    if ($var(tmp)) {
 > > 
 > > fail to figure out that $var(tmp) has value?
 > 
 > You should use if ($var(tmp)!="").
 > if ($var(tmp)) works only for integers. If $var(tmp) is not integer and
 > not a string of the form "1234", it will evaluate to 0 in an integer
 > context. The if() it's an integer context (no boolean context in sr).

thanks for the explanation.  i have to say though that as a normal
programmer, i'm not used to such behavior.

in order to avoid programming mistakes like that, could it be possible
to produce a error message if such a test is attempted, i.e., test on
string valued pvar?

-- juha



More information about the sr-dev mailing list