What is the reason you pad numbers with spaces when decrementing? Is it for
performance? It seems to me that it happens only once per say 10^n times, so
we could afford reallocation of memory even for n=1. But even if I am wrong,
why not just pad it with \0 ? That would make life much easier.
Alternatively you could just move the content to the right, pad it from left
with whatever you like (even spaces) but at the same time move the pointer
one position to the right.

This "feature" combined with Memcache client for PHP and crappy PHP type
coercions results with bugs very difficult to track (on average once per
each hired developer despite the training).
Consider the following example:
<?php
require('autoload.php');
$c = new CacheKey('default','x');
$c->set(9);
$c->increment();
$c->decrement();
$x = $c->get();
var_dump($x);  //you would expect "9", but you get "9 " (extra space)
var_dump($x+1); //you would expect an error, but, PHP somehow knows that "9
" + 1 == 10
++$x; //you would expect that since $x+1 == 10, then ++$x will also work
var_dump($x); //unfortunately it does not, and magically $x is still "9 "
?>

I mean: this is an internal hack/tweak/optimization and should be
transparent to the end user. I know it is documented, but it doesn't make it
more reasonable.

Reply via email to