Skip to content

Let Serde hand back the scalars it accepts - #730

Merged
blaipr merged 1 commit into
mainfrom
fix/serde-round-trips-scalars
Aug 13, 2026
Merged

Let Serde hand back the scalars it accepts#730
blaipr merged 1 commit into
mainfrom
fix/serde-round-trips-scalars

Conversation

@blaipr

@blaipr blaipr commented Aug 13, 2026

Copy link
Copy Markdown
Member

The bug

Serde::serialize() accepts array|object|string|int — and its own test passes a string and an int through it — while Serde::deserialize() was declared to return object|array. So reading either scalar back raised:

TypeError: Serde::deserialize(): Return value must be of type object|array, string returned

Anything that cached a bare scalar could store it and never read it again. FileCache::load() is one call away from that; it only gets away with it today because every caller happens to cache an array or an object.

The fix

Widen the native return type to what the other half accepts.

The phpDoc is left exactly as it is. The parenthesised form that would satisfy the parser reintroduces template-resolution errors at every call site — which is why it carries a baseline entry with that note already. Changing it here would be re-treading a decision that was made and recorded.

The one place the wider type rippled to is the public link view, where the deserialized vault is annotated at the call site instead. Its baseline entry goes with it — the baseline shrinks by one, from 350 to 349.

Testing

The existing serialize provider — a string and an int among them — now runs through deserialize() as well. It fails against the old signature with exactly the TypeError above, for both scalars.

Unit suite green: 3085. PHPStan and PHPCS clean.

serialize() takes a string or an int — its own test passes both through it — but
deserialize() was declared object|array, so reading either back raised a
TypeError on the way out. Anything that cached a bare scalar could store it and
never read it again; the file cache is one call away from that, and today only
gets away with it because every caller happens to cache an array or an object.

Widen the native return type to what the other half accepts. The phpDoc is left
exactly as it was: the parenthesised form that would satisfy the parser
reintroduces template-resolution errors at every call site, which is why it is
baselined with that note.

The one place the wider type rippled to is the public link view, where the
deserialized vault is annotated at the call site instead — so its baseline entry
goes, one fewer than before.
@blaipr
blaipr merged commit 1b5ef48 into main Aug 13, 2026
8 checks passed
@blaipr
blaipr deleted the fix/serde-round-trips-scalars branch August 13, 2026 22:06
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