Why is it that $null + 0 is 0 but not int? What is it?
-- Juha
$avp(test) = $null + 0; if (is_int("$avp(test)")) INFO(test $avp(test) IS int); else INFO(test $avp(test) IS NOT int);
Dec 1 02:46:01 salmon /usr/bin/sip-proxy[10138]: INFO: test 0 IS NOT int
Probably is string, that's the default value type of PVs, as they originated from xlog, where the output was a string to be printed.
"" + 0 should be "0"
Cheers, Daniel
On 01.12.19 02:35, Juha Heinanen wrote:
Why is it that $null + 0 is 0 but not int? What is it?
-- Juha
$avp(test) = $null + 0; if (is_int("$avp(test)")) INFO(test $avp(test) IS int); else INFO(test $avp(test) IS NOT int);
Dec 1 02:46:01 salmon /usr/bin/sip-proxy[10138]: INFO: test 0 IS NOT int
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
I added 0 to $null in order to get int. If I had added "0" the result should be string. So this looks like a bug to me. If I add 0, result can't be string.
Juha
On December 1, 2019 6:08:01 PM GMT+09:00, Daniel-Constantin Mierla miconda@gmail.com wrote:
Probably is string, that's the default value type of PVs, as they originated from xlog, where the output was a string to be printed.
"" + 0 should be "0"
Cheers, Daniel
On 01.12.19 02:35, Juha Heinanen wrote:
Why is it that $null + 0 is 0 but not int? What is it?
-- Juha
$avp(test) = $null + 0; if (is_int("$avp(test)")) INFO(test $avp(test) IS int); else INFO(test $avp(test) IS NOT int);
Dec 1 02:46:01 salmon /usr/bin/sip-proxy[10138]: INFO: test 0 IS NOT
int
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
In all programming languages the first operand gives the type of the expression. That's why it works to concatenate integers to string in the fashion:
"abc" + 123
Try 0 + $null and see if it is integer.
Cheers, Daniel
On 01.12.19 12:29, Juha Heinanen wrote:
I added 0 to $null in order to get int. If I had added "0" the result should be string. So this looks like a bug to me. If I add 0, result can't be string.
Juha
On December 1, 2019 6:08:01 PM GMT+09:00, Daniel-Constantin Mierla miconda@gmail.com wrote:
Probably is string, that's the default value type of PVs, as they originated from xlog, where the output was a string to be printed.
"" + 0 should be "0"
Cheers, Daniel
On 01.12.19 02:35, Juha Heinanen wrote:
Why is it that $null + 0 is 0 but not int? What is it?
-- Juha
$avp(test) = $null + 0; if (is_int("$avp(test)")) INFO(test $avp(test) IS int); else INFO(test $avp(test) IS NOT int);
Dec 1 02:46:01 salmon /usr/bin/sip-proxy[10138]: INFO: test 0 IS NOT
int
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Thanks for the tip. 0 + $null is int. The bug is that $null should be nothing, not an empty string.
-- Juha
It was like this from the beginning, there is a base string type for variables by default.
If people want, then we can reconsider when doing a major refactoring/adjustment to the native interpreter, probably for Kamailio 6.0, as there were some discussions during the last Kamailio Developers Meeting in Dusseldorf and informed to mailing lists.
However, that can result in no-operations with $null values, like it happens now in Lua or Python -- if you want to print or use in expressions NULL, you get an exception, stopping execution of the script for the respective SIP message. That is the reason KEMI has KSR.pv.gete() to return empty string when the value is $null, otherwise the external scripting interpreters throw errors/exceptions when using NULL in expressions.
I still thing that having a loose handling of $null is better that string evaluation to "nothing" -- it can result in a lot of IF conditions to evaluate if a variable can be used in an expression or log or other functions parameters. But again, it can be discussed and reconsidered.
Cheers, Daniel
On 02.12.19 03:50, Juha Heinanen wrote:
Thanks for the tip. 0 + $null is int. The bug is that $null should be nothing, not an empty string.
-- Juha