Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

979 set error unassigned #982

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion changelog/966.md

This file was deleted.

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)
1 change: 1 addition & 0 deletions changelog/979.md
@@ -0,0 +1 @@
- Fixed missing Smarty getErrorUnassigned/setErrorUnassigned methods [#979](https://github.com/smarty-php/smarty/issues/979)
2 changes: 1 addition & 1 deletion make-release.sh
Expand Up @@ -15,7 +15,7 @@ php utilities/update-smarty-version-number.php $1
git add changelog CHANGELOG.md src/Smarty.php
git commit -m "version bump"

git checkout master
git checkout support/5
git pull
git merge --no-ff "release/$1"
git branch -d "release/$1"
Expand Down
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
16 changes: 16 additions & 0 deletions src/Smarty.php
Expand Up @@ -2228,5 +2228,21 @@ private function returnOrCreateTemplate($template, $cache_id = null, $compile_id
return $template;
}

/**
* Whether Smarty displays an error when using an unassigned variable
*/
public function getErrorUnassigned(): bool
{
return (bool) $this->error_unassigned;
}

/**
* Set if Smarty should display an error on using an unassigned variable
*/
public function setErrorUnassigned(bool $error_unassigned): void
{
$this->error_unassigned = $error_unassigned;
}

}

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}')
);
}
}