Ah, now I understand the scribblings on Grubba's whiteboard. :-)
/ Johan Sundström (folkskådare)
Previous text:
2003-04-17 22:26: Subject: lfun::`+=()
Yes. The reason is that the object got more than one reference (one is in o and one is on the stack) and in that case pike won't use the destructive `+= since it wouldn't follow the semantics of the += operator.
An optimization for this has been added in 7.5 recently so that it doesn't trip up on the extra reference from the stack. Your example works there.
In 7.4 and earlier you have to get rid of one reference, which can be done with this trick:
o = o + (o = 0, "bar");
Despite the appearance, pike will use o->`+= since the object only got one reference (on the stack, since o is temporarily set to 0).
/ Martin Stjernholm, Roxen IS