Repository navigation
Reject laminas-db typed parameters in Expression - #268
Merged
simon-mundy merged 2 commits intoDec 1, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
simon-mundy
force-pushed
the
fix/264-typed-expression-parameters
branch
from
November 30, 2026 09:56
3497e6e to
b3799ad
Compare
laminas-db read a single-entry array parameter such as
['a' => 'identifier'] as [value => type]. In 0.6.x every array
parameter becomes an IN (?) list, so inside parentheses the key was
dropped and the type name was bound as the value, rendering
UPPER('identifier') instead of UPPER(`a`) without any error.
Expression::setParameters() now throws InvalidArgumentException for a
single-entry array that is not a list and whose value is one of the
laminas-db type names, pointing to the Argument classes instead. This
covers Predicate\Expression, Predicate::expression() and where()
conditions with placeholders. Real lists, including ['identifier'] and
lists with gapped keys, are still bound as IN (?) values.
The check is a private method on Expression. It takes the class over
mago's cyclomatic complexity limit, which is accepted with an inline
@mago-expect rather than moving the check into a separate class.
Fixes php-db#264
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
simon-mundy
force-pushed
the
fix/264-typed-expression-parameters
branch
from
December 1, 2026 02:38
b3799ad to
a10b212
Compare
tyrsson
approved these changes
Dec 1, 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.
Fixes #264
Problem
laminas-db let an
Expressionparameter carry its own type as a single-entry array,[value => type]. phpdb treats every array parameter as anIN (?)list, so when the placeholder is inside parentheses the type name is bound as the value:new Expression('UPPER(?)', [['a' => 'identifier']])rendersUPPER('identifier')instead ofUPPER(`a`), with no error.Fix
Expression::setParameters()rejects a single-entry, non-list array whose value is exactly one of the laminas type names (identifier,value,literal,select). The check coversPredicate\Expression,Predicate::expression()andwhere(['expr ?' => [...]]), which all go through it.Sql\Exception\InvalidArgumentException::forTypedExpressionParameter(); its message shows the offending pair and points to theArgumentclasses.Expression::validTypedParameter(), which returns the list unchanged when it isn't the typed form. It takesExpressionover mago's cyclomatic complexity limit (17 against 15); that is accepted with an inline@mago-expect lint:cyclomatic-complexityand a reason, as the repo already does elsewhere, rather than moving the check into a separate class.What stays the same
INlists, including['identifier'], lists with gaps in their keys, multi-entry arrays, and single entries whose value isn't a type name.ExpressionInterfaceandArgumentparameters.Tests
ExpressionTest: eight rejected shapes (each type name with a string key and an integer key) through the constructor andsetParameters(), checking class and message; ten accepted shapes.Predicate\ExpressionTest: rejection throughPredicate\Expression.InvalidArgumentExceptionTest: the new named constructor.mago lintis clean andmago analyzereports nothing new.mago formatalso realigned the existing arms of thematchinsetParameters().