Fix SplObjectStorage deprecations on PHP 8.5#29
Merged
Conversation
SplObjectStorage::attach() and ::detach() are deprecated since PHP 8.5.
All 15 call sites in src/ that target an SplObjectStorage now use the
documented replacements, offsetSet($object, null) and offsetUnset($object).
Callback/Composite.php 30, 35
Event/Event.php 51, 56
KeyValue/Composite.php 19, 24
Observer/Subject.php 20, 25
Statemachine/State.php 39
Statemachine/Factory/Factory.php 44, 49
Statemachine/Graph/GraphBuilder.php 91, 99
Statemachine/Observer/SubjectHasUpdated.php 15, 17
Three attach() calls in src/ are left untouched on purpose — they target
Event and Statemachine, which have their own attach(), not SplObjectStorage:
SetupHelper.php:111, StateCollectionMerger.php:149, Factory.php:66.
Equivalence: attach($o) with its default $info also stores null, so
offsetSet($o, null) is identical in behaviour. $info is never used
anywhere in this repository.
Also fixes the four occurrences in tests/.
Verified on PHP 8.5.4:
static: no SplObjectStorage attach/detach left in src/
suite: 12 deprecations -> OK (88 tests, 189 assertions)
uncovered paths (Factory, Event::detach — no test reaches them):
4 deprecations -> 0
example: byte-identical output, 76 lines / 3630 bytes
Metabor
force-pushed
the
fix/php85-splobjectstorage-deprecations
branch
from
July 15, 2026 13:09
02eda2b to
0a74881
Compare
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.
PHP 8.5 deprecates
SplObjectStorage::attach()and::detach(). Fifteen call sites insrc/trigger them, so every consumer running on PHP 8.5 gets deprecation notices coming out of this library.What changes
attach($o)→offsetSet($o, null)anddetach($o)→offsetUnset($o)— the replacements named in the deprecation message.Metabor/Callback/Composite.phpMetabor/Event/Event.phpMetabor/KeyValue/Composite.phpMetabor/Observer/Subject.phpMetabor/Statemachine/State.phpMetabor/Statemachine/Factory/Factory.phpMetabor/Statemachine/Graph/GraphBuilder.phpMetabor/Statemachine/Observer/SubjectHasUpdated.phpPlus the four occurrences in
tests/.Three
attach()calls insrc/are deliberately left alone. They targetEventandStatemachine, which define their ownattach()— notSplObjectStorage:SetupHelper.php:111,StateCollectionMerger.php:149,Factory.php:66. A blind search-and-replace would have broken the public API here.Equivalence
attach($o)storesnullas its$infoby default, andoffsetSet($o, null)does the same — identical in behaviour, including return value, repeated insertion,count(),contains()and iteration.$infois never read anywhere in this repository.Verification
The test suite is not sufficient evidence here, and that is worth spelling out: it only reports deprecations on the code paths it executes.
Factory::attachStatemachineObserver,Factory::detachStatemachineObserver,Event::detach,KeyValue\Composite::detach,GraphBuilderand one branch ofSubjectHasUpdatedare reached by none of the 88 tests. A fix driven by the suite output stops at eight of the fifteen — and the suite then reports success.Three independent checks on PHP 8.5.4:
1. Static — independent of any execution
2. The uncovered paths, driven by hand
A script calling
Factory::attachStatemachineObserver,Factory::detachStatemachineObserverandEvent::detach— none of which any test reaches:3. The suite, for what it is worth
Behaviour
Running Statemachine-Example against the patched library produces byte-identical output (76 lines, 3630 bytes), and drops it from 21 deprecations per run to 0. Those 21 only surface under
error_reporting=E_ALL; the stockphp.inihides them, which is part of why they went unnoticed.Not addressed here
SubjectHasUpdated extends \SplObjectStorage, so the class inherits the deprecatedattach()/detach()into its own public API. Both internal calls are fixed, but the inheritance is a design question, not a deprecation fix.