[sr-dev] trouble with testing $var
Andrei Pelinescu-Onciul
andrei at iptel.org
Tue Nov 10 11:37:23 CET 2009
On Nov 09, 2009 at 22:58, Juha Heinanen <jh at tutpro.com> wrote:
> 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?
We could generate an error message, but only at runtime (because we
don't know the type of $var(tmp) at script compile time).
Andrei
More information about the sr-dev
mailing list