PHP function memcache_decrement gives strange output

Sumit Datta sumitdatta at
Thu Aug 9 18:31:35 UTC 2007

I have come across an issue with memcache_decrement in PHP. I guess
this same will happen with clients in other languages so I am posting
it here. The problem is pretty simple:
* set a key to value 0
* use increment to raise the value (increment by 1 as in default)
* I do a var_dump in PHP which shows normal stuff, which is a string
representing the number. (Of course it should have been an integet
output, but at least the value if OK).
* use decrement to lower the value (decrement by 1 as in default)
* I do a var_dump again and here the outputs are not usual. When value
reduces in the number of digits there appears an extra <space> at the
end of the string shown by var_dump.

Here is a demo code:
the you can check the result:

In this code even with the <space> memcache gets data pretty easily.
This actually caused data fetch errors in one of our codes. Which led
me to this issue. I am not sure why this happens. If i use intval( )
of the needed decremented data from memcache all works fine.
Is this a PHP only error?
=Code is Poetry=
Sumit Datta
Web Developer

More information about the memcached mailing list