Skip to content

Unexpected expression type in QuerySimulation #276

@xPaw

Description

@xPaw
$queries = [ 'SELECT 1' ];

foreach( $queries as $test )
{
	$test = $pdo->prepare( $test ); // reusing variable
	$test->execute();
}

However this doesn't crash:

$test = 'SELECT 1';
$test = Container::Database()->prepare( $test );
$test->execute();

Something about the loop makes it confuse the type. Obviously reusing the variable isn't a good idea (and I fixed it in my code), but it probably shouldn't crash.

Uncaught staabm\PHPStanDba\DbaException: Unexpected expression type [snip] of class PHPStan\Type\Generic\GenericObjectType in phpstan-dba\src\QueryReflection\QuerySimulation.php:117
#0 phpstan-dba\src\QueryReflection\QueryReflection.php(189): staabm\PHPStanDba\QueryReflection\QuerySimulation::simulateParamValueType(Object(PHPStan\Type\Generic\GenericObjectType), false)
#1 phpstan-dba\src\QueryReflection\QueryReflection.php(165): staabm\PHPStanDba\QueryReflection\QueryReflection->resolveQueryStringExpr(Object(PhpParser\Node\Expr\Variable), Object(PHPStan\Analyser\MutatingScope))
#2 phpstan-dba\src\QueryReflection\QueryReflection.php(137): staabm\PHPStanDba\QueryReflection\QueryReflection->resolveQueryExpr(Object(PhpParser\Node\Expr\Variable), Object(PHPStan\Analyser\MutatingScope))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions