Skip to content

Commit

Permalink
Fix Smarty::assign() not returning when called with an array as first…
Browse files Browse the repository at this point in the history
… parameter. (#973)

Fixes #972
  • Loading branch information
wisskid authored Mar 28, 2024
1 parent 4fec27c commit 6f054ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/972.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function assign($tpl_var, $value = null, $nocache = false, $scope = null)
foreach ($tpl_var as $_key => $_val) {
$this->assign($_key, $_val, $nocache, $scope);
}
return;
return $this;
}
switch ($scope ?? $this->getDefaultScope()) {
case self::SCOPE_GLOBAL:
Expand Down
11 changes: 11 additions & 0 deletions tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ public function testArrayAssign()
$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}')
);
}
}

0 comments on commit 6f054ec

Please sign in to comment.