Fix Smarty::assign() not returning when called with an array as first parameter. (#973)

Fixes #972
This commit is contained in:
Simon Wisselink
2024-03-28 11:22:29 +01:00
committed by Simon Wisselink
parent 569cef71d0
commit 599bcee13e
3 changed files with 13 additions and 1 deletions

1
changelog/972.md Normal file
View File

@@ -0,0 +1 @@
- Fix Smarty::assign() not returning $this when called with an array as first parameter [#972](https://github.com/smarty-php/smarty/pull/972)

View File

@@ -109,7 +109,7 @@ class Data
foreach ($tpl_var as $_key => $_val) {
$this->assign($_key, $_val, $nocache, $scope);
}
return;
return $this;
}
switch ($scope ?? $this->getDefaultScope()) {
case self::SCOPE_GLOBAL:

View File

@@ -42,4 +42,15 @@ class AssignTest extends PHPUnit_Smarty
$this->smarty->assign(array('foo' => 'bar', 'foo2' => 'bar2'));
$this->assertEquals('bar bar2', $this->smarty->fetch('eval:{$foo} {$foo2}'));
}
/**
* Test that assign returns this.
*/
public function testAssignReturnsThis()
{
$this->assertEquals(
'data',
$this->smarty->assign(['dummy' => 'data'])->fetch('eval:{$dummy}')
);
}
}