Repository navigation
Make public constants final and type NAMED_ADAPTER_KEY - #251
Merged
Merged
Conversation
Mark the 38 public constants that nothing in phpdb or the driver packages redeclares as final, so implementers and subclasses cannot override them. Since PHP 8.1 an implementing class can override an interface constant unless it is final. The SPECIFICATION_* constants on Insert, Update and Delete and HOLDS_MAPPED_ROWS stay overridable, since subclasses override them by design. ConfigProvider::NAMED_ADAPTER_KEY gains its missing string type, which clears its analyzer baseline entry.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
tyrsson
approved these changes
Nov 17, 2026
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.
Problem
An audit of every class constant on
0.6.x, done with PHP reflection over all classes, interfaces, traits and enums insrc/andtest/, found two gaps insrc/:ConfigProvider::NAMED_ADAPTER_KEYis the only one that isn't.final: 45 public or protected constants are notfinal. Since PHP 8.1 a class that implements an interface can override the interface's constants unless they arefinal, and a subclass can override a parent's.Fix
Type
ConfigProvider::NAMED_ADAPTER_KEYasstring. This also removes itsmissing-constant-typeentry from the analyzer baseline.Make 38 constants
final. Nothing in phpdb, phpdb-mysql, phpdb-sqlite or phpdb-pgsql redeclares them. The drivers only read them, e.g.AdapterInterface::QUERY_MODE_EXECUTEandParameterContainer::TYPE_*.Adapter\AdapterInterfaceQUERY_MODE_*,PREPARE_TYPE_*,FUNCTION_*,VALUE_QUOTE_SEPARATOR(8)Adapter\Driver\DriverInterfacePARAMETERIZATION_*(2)Adapter\Driver\Pdo\ResultSTATEMENT_MODE_*,VALID_FETCH_MODES(3)Adapter\ParameterContainerTYPE_*(7)Metadata\Source\AbstractSourceDEFAULT_SCHEMA, a sentinel the drivers read throughself::(1)ResultSet\ResultSetTYPE_ARRAYOBJECT,TYPE_ARRAY(2)Sql\SqlInterfaceTYPE_IDENTIFIER,TYPE_VALUE,TYPE_LITERAL,TYPE_SELECT(4)TableGateway\Feature\EventFeatureEventsInterfaceEVENT_*(10)TableGateway\Feature\FeatureSetAPPLY_HALT(1)Left overridable on purpose
Insert::SPECIFICATION_INSERT,Update::SPECIFICATION_UPDATEandDelete::SPECIFICATION_DELETE: overriding these is how a subclass makes anINSERT IGNORE/REPLACE/UPDATE IGNORE/DELETE IGNOREstatement, as theReplace,UpdateIgnoreandDeleteIgnoretest assets do.AbstractResultSet::HOLDS_MAPPED_ROWSandHydratingResultSet::HOLDS_MAPPED_ROWS:HydratingResultSetoverrides the parent's value.ConfigProvider::NAMED_ADAPTER_KEYandTableIdentifier::SEPARATOR: both classes arefinal, so their constants cannot be overridden anyway.final.BC
Third-party code that redeclares one of the 38 constants in a subclass or an interface implementation will now fail with a fatal error. Nothing in phpdb or the three driver packages does, and the constants are enum-like values that should not be redefined. Worth a line in the release notes.
Verification
mago format --check,mago lint,mago analyzeandmago guardexit 0 on PHP 8.3, 8.4 and 8.5. The analyzer baseline no longer has a stale entry.