You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A null expression parameter raises TypeError when prepared and renders '' in getSqlString() #207
AbstractSql::processExpression() renders a Sql\Argument\Value in one of two ways (AbstractSql.php#L234-L242):
With a parameter container, it calls processExpressionParameterName(), whose $value is int|float|string|bool (AbstractSql.php#L285). Value::getValue() can return null, which raises a TypeError.
Without one, it calls quoteValue((string) $argument->getValue()), which turns null into a quoted empty string.
So a = ? with null either fails to prepare or renders a = '', a different query. This affects every predicate holding a null Value, including expression(), equalTo() and the other comparison methods.
Column values already render null as SQL NULL: resolveColumnValue() returns 'NULL' for a null column, so Insert and Update produce VALUES (:id, NULL) in prepared mode too.
The '' expectation in PredicateTest dates from laminas-db (1c5ad3a, 2022), which recorded what quoting null produced at the time. That test never reaches its assertion on 0.6.x: its helper expects Sql92 to refuse the quote and throw.
Steps to Reproduce
(new Select('t'))->where(new Predicate\Expression('COALESCE(?, 7) = 7', [null])), prepared and executed on SQLite.
The same predicate rendered with getSqlString() on any driver platform.
Expected Behavior
NULL, i.e. COALESCE(NULL, 7), in both modes, consistent with resolveColumnValue().
Inlining NULL changes the SQL text depending on whether a value is null. The alternative is to bind null as a parameter, which keeps one statement shape for statement caching (see #112). That means widening processExpressionParameterName() to accept null, which breaks subclasses that override it with the current signature. No driver package overrides it.
Actual behavior?
Prepared:
TypeError: PhpDb\Sql\AbstractSql::processExpressionParameterName(): Argument #1 ($value) must be of type string|int|float|bool, null given
Activity
simon-mundy commentedon Nov 30, 2026
Re-checked on current 0.6.x (
7a142543), #259 and the render-time dialect branch in #261. All three behave the same.The prepared half is fixed: a null expression parameter now binds as null.
The
getSqlString()half remains: null still renders as'', from the(string)cast inAbstractSql::processExpression().It reaches further than the predicates listed above. The same cast turns null into
''for:in('a', [1, null])andwhere(['a' => [1, null]])Argument::value(null)in a predicateExpressionparameter incolumns()ororder()Expressionvalue inInsert::values()orUpdate::set()Argument::value(null), which rendersDEFAULT ''The same cast applied to
falseis filed separately as #262.