Skip to content

Merge 2.0.x into 2.1.x - #246

Merged
DavidBadura merged 13 commits into
2.1.xfrom
2.0.x-merge-up-into-2.1.x
Nov 7, 2026
Merged

DavidBadura merged 13 commits into
2.1.xfrom
2.0.x-merge-up-into-2.1.x

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

Brings the 1.24.4 fixes from #244 into 2.1.x: nullable collection items get a normalizer again, handleType skips shape keys missing in the docblock, and mergeMetadata() lets the child win over the parent. The array shape key handling from #241 was already here, so only the test files needed resolving, both sides kept.

ArrayShapeNormalizer only returned the keys it had an inner normalizer for,
so every other key of the shape was silently dropped on extract and hydrate.
Keys holding null were dropped too because of isset(). The normalizer now
works on the given array and only converts the keys it has a normalizer for,
null included, and keeps everything else as it is, like ArrayNormalizer and
plain arrays do.
The collection branch unwrapped the nullable item type from the collection
itself instead of from the item type, so collections like list<?Skill> got no
normalizer at all and their items were passed through as raw objects.
An explicit ArrayShapeNormalizer map can contain keys that the property's
docblock shape doesn't know. handleType read those keys anyway and raised
undefined key warnings. Such fields are now left alone, like the whole map is
when the property type isn't an array shape.
The collection and array shape branches unwrapped nullable item types and
looked for a class normalizer before recursing, although inferNormalizerByType
does both on its own. Dropping the duplicate removes the place where the
nullable item bug came from. The shape branch is now also covered in the
metadata factory test.
The parameter names of mergeMetadata() were swapped relative to the call site,
so the lazy flag of the parent took precedence over the child's. A class with
#[Lazy(false)] extending a #[Lazy] class was still hydrated lazily. Everything
else keeps its current order: properties, callbacks and the data subject id of
the child still come first.
getMethods() already returns the public and protected methods a class inherits,
and mergeMetadata() added the parent's callbacks on top, so an inherited
#[PostHydrate] or #[PreExtract] method was called twice. An overridden one ran
as the child's version and then again as the parent's, because the parent's
reflection method was invoked directly. The merge now resolves every callback to
the method PHP would call on the child and keeps it once. An override runs as
the child's version, also when it doesn't repeat the attribute. Private methods
of the parent are not inherited and stay as they are.
The array and array shape examples used #[ArrayNormalizer] and
#[ArrayShapeNormalizer] without arguments, which fails because both constructors
require the inner normalizers. In these cases the normalizer is inferred from
the docblock, so the attribute is dropped and the text says so. A few other
examples had typos that made them invalid PHP, like a misspelled class name,
missing semicolons and a match arm written as a case.
Normalizers get null for nullable properties and, since the array shape fix,
for null values in shapes as well, so the example should not reject it.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Hello 👋

Here are the most recent benchmark results, compared against 2.1.x. Time is the mode over the iterations in the its column, with the relative standard deviation in brackets.

StackHydrator

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb -21.21% 1.998μs (±0.68%) 1.986μs (±37.12%) -0.61%
benchExtract1Object 1000 5 1.856mb -21.21% 2.348μs (±1.22%) 2.456μs (±1.59%) +4.62%
benchHydrate1000Objects 3 5 1.856mb -21.21% 1.977ms (±1.30%) 1.946ms (±1.07%) -1.56%
benchExtract1000Objects 3 5 1.856mb 0.00% 1.939ms (±0.33%) 1.949ms (±0.92%) +0.52%

StackHydratorWithCryptography

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 3.073μs (±1.84%) 3.022μs (±0.93%) -1.65%
benchExtract1Object 1000 5 1.856mb 0.00% 7.436μs (±7.88%) 7.331μs (±1.39%) -1.41%
benchHydrate1000Objects 3 5 1.856mb 0.00% 3.011ms (±1.50%) 2.962ms (±1.60%) -1.62%
benchExtract1000Objects 3 5 1.856mb 0.00% 6.927ms (±0.56%) 6.901ms (±1.02%) -0.37%

StackHydratorWithLazy

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 0.357μs (±1.71%) 0.359μs (±1.66%) +0.36%
benchHydrate1ObjectTriggerInit 1000 5 1.856mb 0.00% 2.590μs (±0.68%) 2.604μs (±0.61%) +0.55%
benchHydrate1000Objects 3 5 1.856mb 0.00% 350.972μs (±1.45%) 350.243μs (±1.67%) -0.21%
benchHydrate1000ObjectsTriggerInit 3 5 1.856mb 0.00% 2.587ms (±0.88%) 2.590ms (±0.34%) +0.11%

This comment gets updated every time a new commit comes in.

@DavidBadura
DavidBadura merged commit 1a71665 into 2.1.x Nov 7, 2026
17 checks passed
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