You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: MemcachedHandler::decrement() produces the opposite sign of File/Redis/Predis for a non-existent key #10510
Which operating systems have you tested for this bug?
macOS
Which server did you use?
cli-server (PHP built-in webserver)
Environment
development
Database
No response
What happened?
Description
MemcachedHandler::decrement() behaves inconsistently with the other cache
handlers (File, Redis, Predis) when the key being decremented does not
yet exist. This is already flagged in the code with a // FIXME comment,
but not resolved:
Now try the same thing with File, Redis, or Predis instead — they all give:
$cache->decrement('brand_new_key', 5);
// -> -5
What I'd expect
If I decrement a key by 5, I'd expect a negative number back when it starts from nothing — like every other handler does. Memcached gives the opposite sign, which feels like a bug you could easily not notice until you switch cache drivers between dev and prod and your numbers suddenly flip.
Why this happens
I checked the PHP docs for Memcached::decrement() — the 3rd argument (initial_value) is used as-is if the key doesn't exist yet, it's not something the offset gets subtracted from. So passing $offset there just plants the key at +$offset instead of decrementing from zero.
(increment() doesn't have this problem, by the way — it's just a lucky coincidence that 0 + $offset and passing $offset as the initial value land on the same number.)
Hi @nightcityblade, thanks for offering to help! Just so you know, I already made a PR for this: #10512. Feel free to check it out — if you see anything wrong, or have a different idea, let me know.
Activity
nightcityblade commentedon Aug 31, 2026
Hi, I'd like to work on this. I'll submit a focused fix with regression coverage shortly.
mdalikadar commentedon Aug 31, 2026
Hi @nightcityblade, thanks for offering to help! Just so you know, I already made a PR for this: #10512. Feel free to check it out — if you see anything wrong, or have a different idea, let me know.