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
The public field SelectStatement::$expr is defined in a PHP docblock as an Expression[]. When parsing a query with a CASE statement, a CaseExpression object is present in this list, despite CaseExpression not extending Expression. This causes issues when explicitly requiring the Expression type as should be returned by SelectStatement::$expr.
Reproduction case
<?phpdeclare(strict_types=1);
usePhpMyAdmin\SqlParser\Components\Expression;
usePhpMyAdmin\SqlParser\Parser;
usePhpMyAdmin\SqlParser\Statements\SelectStatement;
include_once'vendor/autoload.php';
$p = newParser('SELECT a, CASE WHEN b IS NOT NULL THEN 1 ELSE 0 END as c FROM t');
$stmt = $p->statements[0];
if (! $stmtinstanceof SelectStatement) {
thrownewException('Could not parse select statement');
}
functionacceptExpression(Expression$e): void {}
$expressions = $stmt->expr;
foreach ($expressionsas$expression) {
acceptExpression($expression);
}
Expected behavior
I would expect this script to not error out as the $stmt->expr returns Expression[] according to its PHP docblock. Each element should therefore be compatible with Expression in my acceptExpression function.
Real behavior
$ php test.php
PHP Fatal error: Uncaught TypeError: acceptExpression(): Argument #1 ($e) must be of type PhpMyAdmin\SqlParser\Components\Expression, PhpMyAdmin\SqlParser\Components\CaseExpression given, called in /path/to/test.php on line 22 and defined in /path/to/test.php:18
Stack trace:
#0 /path/to/test.php(22): acceptExpression()
#1 {main}
thrown in /path/to/test.php on line 18
The text was updated successfully, but these errors were encountered:
I noticed this issue before but I have no idea how to fix this. CaseExpression cannot inherit from Expression, but all of the code is written around the value being only Expression.
#583 Defines now that SelectStatement::$expr can be of type CaseExpression[]. @Daniel-I-Am , your snippet will still cause an error as this is just a change in the PHPDoc, but at least, the PHPDoc will be valid and you could change your behavior to
The public field
SelectStatement::$expr
is defined in a PHP docblock as anExpression[]
. When parsing a query with aCASE
statement, aCaseExpression
object is present in this list, despiteCaseExpression
not extendingExpression
. This causes issues when explicitly requiring theExpression
type as should be returned bySelectStatement::$expr
.Reproduction case
Expected behavior
I would expect this script to not error out as the
$stmt->expr
returnsExpression[]
according to its PHP docblock. Each element should therefore be compatible withExpression
in myacceptExpression
function.Real behavior
The text was updated successfully, but these errors were encountered: