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.

Fixes #972
  • Loading branch information
wisskid committed Mar 28, 2024
1 parent 4fec27c commit 547b32a
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
@@ -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
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
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 547b32a

Please sign in to comment.