Fix an empty destructuring pattern triggering a PHP fatal error instead of a SyntaxError

This commit is contained in:
Fabien Potencier
2026-08-23 09:50:46 +02:00
parent cd25fe5b98
commit a2b023397e
3 changed files with 23 additions and 0 deletions
+19
View File
@@ -268,6 +268,25 @@ class ExpressionParserTest extends TestCase
$this->assertSame('third', $pairs[2]['value']->getAttribute('name'));
}
/**
* @dataProvider getEmptyDestructuringTests
*/
#[DataProvider('getEmptyDestructuringTests')]
public function testEmptyDestructuringThrows(string $template): void
{
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Cannot destructure to an empty list of variables');
$env->compileSource(new Source($template, 'index'));
}
public static function getEmptyDestructuringTests()
{
yield ['{% do [] = values %}'];
yield ['{% do {} = values %}'];
}
public function testObjectDestructuringUsesAssignmentTargets(): void
{
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);