Repository navigation
Conversation
Metadata::lazy($loader) returns metadata whose entries a loader provides on first use. The first call that reads or alters it (has(), get(), set(), remove(), array access, count(), iteration, toArray(), jsonSerialize()) calls the loader once, and the result is read exactly like constructor input. Loading isn't a change, and hasChanged() never calls the loader, so a store can skip metadata that was never used without fetching it. If the loader throws, the metadata stays unloaded and the next call retries. A call that set() or offsetSet() rejects for its arguments doesn't load. Serializing lazy metadata loads it, then writes PHP's default format without the loader, so metadata serialized with 1.2 still unserializes and eager metadata serializes byte for byte as before. That's done in __serialize() rather than __sleep(): released setono/client-bundle versions make lazy ghosts with Symfony's LazyGhostTrait, whose __serialize() raises notices for __sleep() names it can't resolve. As a consequence, a __sleep() defined in a subclass is no longer used. A clone of unloaded lazy metadata is lazy too and loads on its own. This lets setono/client-bundle drop LazyGhostTrait, which Symfony deprecated in 7.3 and removed in 8.0 (Setono/client-bundle#31). Closes #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Metadata::lazy($loader)creates metadata whose entries a loader provides on first use.hasChanged()never calls the loader, so a store can skip metadata that was never used without fetching it. This lets setono/client-bundle dropLazyGhostTrait, which Symfony deprecated in 7.3 and removed in 8.0 (Setono/client-bundle#31).What it replaces in the bundle:
__serialize()is used instead of the__sleep()the issue suggests. Released bundle versions make lazy ghosts withLazyGhostTrait, and its__serialize()raises anE_USER_NOTICEfor each__sleep()name it can't resolve.set()/offsetSet()calls rejected for their arguments don't load.Evidence
Metadata::lazy()doesn't exist.masterand this branch, so eager metadata serializes as before.Metadata.php. Only the 4 knownClient.phpones remain.roave-backward-compatibility-check --from=origin/master("No backwards-incompatible changes detected").LazyGhostTrait(symfony/var-exporter 7.3) with the bundle's 2.xLazyMetadataand 1.xChangeAwareMetadata/LazyChangeAwareMetadatain a scratch script, run onmasterand on this branch:remove(), and serialization, with no notices.After: output identical to
masterbyte for byte, with no notices. The same script with a__sleep()variant raised 4E_USER_NOTICEs.Merge Danger
Door: two-way
Revertable until 1.3.0 is tagged. After that,
lazy()is public API the bundle will depend on.Blast Radius: serialization
Every
Metadatanow has__serialize(). The bytes are unchanged, but a subclass that defines its own__sleep()will have it ignored, because the inherited__serialize()takes precedence. No released bundle class defines one.new Metadata($array)behaves as before.Closes #8