[SR-Dev] new operators & if($v) behaviour

Andrei Pelinescu-Onciul andrei at iptel.org
Fri Apr 24 11:47:22 CEST 2009


Right now we have a problem with old scripts that use things like
if ($v)  (where $v could be avp, pseudovar or select).

$v can evaluate to a int, a string or undefined.

Now for string and undefined the if will evaluate to false (string
being an error) and an error will be logged.
If the type of $v can be found prior to runtime (e.g. @select is always
string) you'll even get a parse error.

I plan to add some new operators, to properly deal with these cases:

defined($v)

strempty($v)
strlen($v)

but the question still remains if we should preserve compatibility and
still support things like if (@to.tag), instead of if (!strempty(@to.tag))
or if (@to.tag!="").

What's trickier is that if we allow strings in int expressions
then we have 2 problems:

- "" evaluates to 1 or 0?
- how to evaluate a string in an integer context: is "abc" 1 or 3
  (strlen)? How about "123" ?
- $v is 0 if v is not defined?

Note that if we do this it will work in all types of expressions, e.g.
 if string evaluates to strlen(string) in interger context then:
3+"abc" = 6 ; 3+ ""=3 ; 3+"9"=4 3+"0"=4.


Andrei



More information about the sr-dev mailing list