I think that what the book implies is that if the type of $a and $b are of a similar type as a scalar (or untyped), and not necessary a number or string, you have to use a temporary variables to swap as all your methods above use some assumed property of the data type to make the swap "more efficient". I would still think that the
is going to be near optimal for any data type, and will be the optimal one when the type of $a and $b is not preset or may be different.