4 ms·
AIUI, if I do: $x = new Number(-3.2); $y = $x->absolute(); Then not only is $y equal to 3.2, $x is now 3.2 as well. Is this correct? If it is, I think
by cabalamat 13y ago
AIUI, if I do:
$x = new Number(-3.2);
$y = $x->absolute();
Then not only is $y equal to 3.2, $x is now 3.2 as well. Is this correct? If it is, I think it is non-intuitive.
- agumonkey 13y agoAbsolutely.
- niteshade 13y agoAbsolutely non-intuitive?
- gh0zt 13y agoI think the point here is that you'd have to do something like this $x = new Number(1) $y = clone $x; $y->absolute(); to work with the absolute value of variable $x without actually changing $x
- agumonkey 13y agoYes, this is a common source of bugs when you're not sure what is changing. See below, someone suggests to use 'to' and 'as' prefix to convey immutable / mutable methods.
- niteshade 13y agoThat is correct. What would you expect it to do?
- cabalamat 13y agoI would expect $x to remain the same. What's wrong with: $x = -3.2; $y = abs($x);