Skip to content

Reject laminas-db operand types in comparison predicates - #267

Merged
simon-mundy merged 1 commit into
php-db:0.6.xfrom
simon-mundy:fix/263-comparison-type-arguments
Dec 1, 2026
Merged

simon-mundy merged 1 commit into
php-db:0.6.xfrom
simon-mundy:fix/263-comparison-type-arguments

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Fixes #263

Problem

laminas-db's comparison methods took $leftType and $rightType. phpdb's take two arguments, and PHP ignores surplus arguments to a userland method, so migrated code such as equalTo('a', 'b', 'identifier', 'identifier') runs without error but compares column a with the string 'b'. new Operator($left, $op, $right, $leftType, $rightType) has the same problem.

Fix

  • equalTo(), notEqualTo(), lessThan(), lessThanOrEqualTo(), greaterThan() and greaterThanOrEqualTo() throw when given more than two arguments; Operator::__construct() throws when given more than three.
  • The exception is Predicate\Exception\InvalidArgumentException::forRemovedOperandTypes(). Its message names the method and points to Argument::identifier() / Argument::value().
  • where-having.md already notes that the type arguments were removed; it now also says that passing them throws.

What stays the same

  • Every two-argument comparison call and three-argument Operator, including Argument operands.
  • Named arguments: leftType: already fails with "Unknown named parameter".

Tests

  • PredicateTest: a data provider over the six methods checks the exception class and message for four arguments and for a third argument alone, and that two-argument calls still work.
  • OperatorTest: four and five arguments are rejected; three are accepted.
  • The 14 rejection tests fail without the fix. Unit suite: 2896 tests pass. mago lint is clean and mago analyze reports nothing new.

mago format also realigned two existing match blocks in Operator.php, which were already unformatted on 0.6.x.

@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's equalTo(), notEqualTo(), lessThan(), lessThanOrEqualTo(),
greaterThan(), greaterThanOrEqualTo() and the Operator constructor took
$leftType and $rightType. Those parameters are gone, but PHP accepts
surplus positional arguments, so migrated code that still passes them
keeps running and silently compares a column with a string literal
instead of two columns.

Throw InvalidArgumentException::forRemovedOperandTypes() when the extra
arguments are passed, naming the method and pointing to the Identifier
and Value arguments that replace them.

Fixes php-db#263

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
@simon-mundy
simon-mundy force-pushed the fix/263-comparison-type-arguments branch from 3027d7b to 0ef2b36 Compare December 1, 2026 02:38
@simon-mundy
simon-mundy merged commit 1805142 into php-db:0.6.x Dec 1, 2026
15 checks passed
@tyrsson tyrsson added this to the 0.6.0 milestone Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants