[OpenSIPS-Users] coding style / {param.exists, name} and {param.value, name}

Kingsley Tart kingsley at dns99.co.uk
Fri May 21 10:44:28 EST 2021


Hi,

Is one of these methods specifically preferred over another? The first
seems more explicit, but seems to me that OpenSIPS would have to parse
the param list twice - once to check whether the param exists and then
again to get the value. Is the second method acceptable?


Method 1:

if ($(var(pstring){param.exists,customparam})) {
    $var(pval) = $(var(pstring){param.value,customparam});
    # do other stuff
}


Method 2:

$var(pval) = $(var(pstring){param.value,customparam});
if ($var(pval) != NULL {
    # do other stuff
}


There is a functional difference between them that in method 1, if the
param doesn't exist then $var(pval) doesn't get set (it might already
exist with a different value), but if this didn't matter in the context
of the code, is one way preferred over the other?

Cheers,
Kingsley.




More information about the Users mailing list