Hi Andrei,
On 04/24/2009 11:47 AM, Andrei Pelinescu-Onciul wrote:
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((a)to.tag))
or if (@to.tag!="").
I vote fore keeping the support for "if (@to.tag)" like expressions, and
adding the extra functions for more precise checks if necessary. So a
string value could evaluate to true if it exists and not "".
I think it is easier to read and understand "if (@to.tag)" then "if
(!strempty((a)to.tag))"
I was already planning to add the above functions to SER about a year
ago, and we had a discussion about this in the list, but we did not need
these functions in the script so far. I think they would be needed only
for example when there is a parameter in a header field without any
value, and one would like to check the existence of the param.
What's trickier is that if we allow strings in int expressions
then we have 2 problems:
- "" evaluates to 1 or 0?
"" meant 0, changing it to the opposite would be quite confusing.
- how to evaluate a string in an integer context: is
"abc" 1 or 3
(strlen)? How about "123" ?
What do you mean by integer context? Like
if (123 == "abcd") {...} ?
3+"3" ?
Or when a function needs integer parameter but gets string for example?
I am in favour of trying to convert the string to integer, and return an
error when it is not possible. strlen() function can be also supported
in the script, and called explicitly when needed.
- $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.
Miklos
Andrei
_______________________________________________
sr-dev mailing list
sr-dev(a)lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev