PHP function memcache_decrement gives strange output

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


Hello!
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:
http://hispanito.com/memcache_decrement.phps
the you can check the result:
http://hispanito.com/memcache_decrement.php

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?
--
Thanks
=Code is Poetry=
Sumit Datta
Web Developer


More information about the memcached mailing list