Method `+()
- Method
`+
mixed`+(mixedarg)
mixed`+(objectarg,mixed...more)
int`+(intarg,int...more)
float`+(float|intarg,float|int...more)
string`+(string|float|intarg,string|float|int...more)
array`+(arrayarg,array...more)
mapping`+(mappingarg,mapping...more)
multiset`+(multisetarg,multiset...more)- Description
Addition/concatenation.
Every expression with the
+operator becomes a call to this function, i.e.a+bis the same aspredef::`+(a,b). Longer+expressions are normally optimized to one call, so e.g.a+b+cbecomespredef::`+(a,b,c).- Returns
If there's a single argument, that argument is returned.
If
argis an object with only one reference and an lfun::`+=(), that function is called with the rest of the arguments, and its result is returned.Otherwise, if
argis an object with an lfun::`+(), that function is called with the rest of the arguments, and its result is returned.Otherwise, if any of the other arguments is an object that has an lfun::``+(), the first such function is called with the arguments leading up to it, and `+() is then called recursively with the result and the rest of the arguments.
Otherwise, if
argis UNDEFINED and the other arguments are either arrays, mappings or multisets, the first argument is ignored and the remaining are added together as described below. This is useful primarily when appending to mapping values sincem[x] += ({foo})will work even ifm[x]doesn't exist yet.Otherwise the result depends on the argument types:
int|floatThe result is the sum of all the arguments. It's a float if any argument is a float.
string|int|floatIf any argument is a string, all will be converted to strings and concatenated in order to form the result.
arrayThe array arguments are concatened in order to form the result.
mappingThe result is like
argbut extended with the entries from the other arguments. If the same index (according to hash_value and `==) occur in several arguments, the value from the last one is used.multisetThe result is like
argbut extended with the entries from the other arguments. Subsequences with orderwise equal indices (i.e. where `< returns false) are concatenated into the result in argument order.The function is not destructive on the arguments - the result is always a new instance.
- Note
In Pike 7.0 and earlier the addition order was unspecified.
The treatment of UNDEFINED was new in Pike 7.0.
- See also