Skip to content

Reject laminas-db typed parameters in Expression - #268

Merged
simon-mundy merged 2 commits into
php-db:0.6.xfrom
simon-mundy:fix/264-typed-expression-parameters
Dec 1, 2026
Merged

simon-mundy merged 2 commits into
php-db:0.6.xfrom
simon-mundy:fix/264-typed-expression-parameters

Conversation

@simon-mundy

@simon-mundy simon-mundy commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #264

Problem

laminas-db let an Expression parameter carry its own type as a single-entry array, [value => type]. phpdb treats every array parameter as an IN (?) list, so when the placeholder is inside parentheses the type name is bound as the value: new Expression('UPPER(?)', [['a' => 'identifier']]) renders UPPER('identifier') instead of UPPER(`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 covers Predicate\Expression, Predicate::expression() and where(['expr ?' => [...]]), which all go through it.
  • The exception is Sql\Exception\InvalidArgumentException::forTypedExpressionParameter(); its message shows the offending pair and points to the Argument classes.
  • The check is a private method, Expression::validTypedParameter(), which returns the list unchanged when it isn't the typed form. It takes Expression over mago's cyclomatic complexity limit (17 against 15); that is accepted with an inline @mago-expect lint:cyclomatic-complexity and a reason, as the repo already does elsewhere, rather than moving the check into a separate class.

What stays the same

  • Real IN lists, including ['identifier'], lists with gaps in their keys, multi-entry arrays, and single entries whose value isn't a type name.
  • Scalar parameters, ExpressionInterface and Argument parameters.

Tests

  • ExpressionTest: eight rejected shapes (each type name with a string key and an integer key) through the constructor and setParameters(), checking class and message; ten accepted shapes.
  • Predicate\ExpressionTest: rejection through Predicate\Expression.
  • InvalidArgumentExceptionTest: the new named constructor.
  • Unit suite: 2904 tests pass. mago lint is clean and mago analyze reports nothing new. mago format also realigned the existing arms of the match in setParameters().
@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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
simon-mundy force-pushed the fix/264-typed-expression-parameters branch from b3799ad to a10b212 Compare December 1, 2026 02:38
@simon-mundy simon-mundy added this to the 0.6.0 milestone Dec 1, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Dec 1, 2026
@simon-mundy simon-mundy added bug Something isn't working documentation Improvements or additions to documentation qa Improvements in quality assurance of the project labels Dec 1, 2026
@simon-mundy simon-mundy self-assigned this Dec 1, 2026
@simon-mundy
simon-mundy requested a review from tyrsson December 1, 2026 02:51
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in @phpdb Dec 1, 2026
@simon-mundy
simon-mundy merged commit fbf1d1d into php-db:0.6.x Dec 1, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in @phpdb Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation qa Improvements in quality assurance of the project

2 participants