Skip to content

fix(serialization): accept non-string stored values in deserializeValue#6

Merged
ralflang merged 1 commit into
FRAMEWORK_6_0from
fix/serialization-trait-non-string
Jul 1, 2026
Merged

fix(serialization): accept non-string stored values in deserializeValue#6
ralflang merged 1 commit into
FRAMEWORK_6_0from
fix/serialization-trait-non-string

Conversation

@ralflang

@ralflang ralflang commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Reported on the horde mailing list: with Memcache configured, IMP dynamic view crashes on the ThemesCache read path:

```
TypeError: Horde\HashTable\Driver\Memcache::deserializeValue(): Argument #1 ($stored) must be of type string, int given, called in .../Driver/Memcache.php on line 99
and defined in .../SerializationTrait.php:57
```

Root cause

`HashTable\Driver\Memcache::getMultiple()` calls `$this->deserializeValue($val)` on every hit, where `$val` is what `MemcacheApi::getItems()` returns after its own `unserialize()` pass (see `MemcacheApi.php:583`).

The value in that slot is not always a string. Any of the following puts a non-prefixed value into the same memcached pool:

  • The legacy `Horde_HashTable_Memcache` driver (still in `lib/`) writes raw values with no `s:`/`p:` prefix.
  • The legacy `Horde_Cache_Storage_Hashtable::set()` branch (`lib/Horde/Cache/Storage/Hashtable.php:128`) stores `time()` as an int for the timestamp slot.
  • Prior releases of this package running against the same pool before the upgrade.
  • Any co-tenant component using `MemcacheApi` directly.

`SerializationTrait` already documents the intent to be forgiving ("Legacy data without prefix — treat as raw string", line 65–66), but the `string $stored` type declaration prevents that branch from ever running for non-strings and throws a TypeError instead.

Change

`SerializationTrait::deserializeValue()` now takes `mixed` and passes non-strings through unchanged. String values still go through the `s:`/`p:` prefix protocol; unprefixed strings still fall through to the documented raw-string path.

New unit tests in `test/src/Unit/SerializationTraitTest.php` cover:

  • string / int / array round trips through `serialize`+`deserialize`
  • non-string inputs (int, bool, null, array) pass through
  • unprefixed strings return as raw
  • `s:`-prefixed strings whose payload happens to start with `p:` are not misclassified

Fixes the mailing-list crash without changing behaviour for values written by the modern writer.

@ralflang ralflang merged commit 6bb4dda into FRAMEWORK_6_0 Jul 1, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant