From 867154c6a59384ddebe381f14b768b29d4be7fd0 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Wed, 18 Aug 2021 23:08:24 +0200 Subject: [PATCH] Rename setPHP7CompatMode/getPHP7CompatMode for clarity --- CHANGELOG.md | 2 +- libs/Smarty.class.php | 10 +++++----- libs/sysplugins/smarty_internal_templatebase.php | 2 +- .../UndefinedTemplateVar/UndefinedTemplateVarTest.php | 6 +++--- .../PluginFunctionHtmlCheckboxesTest.php | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6532930..069e7056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- You can now use `$smarty->setPHP7CompatMode()` to activate php7 compatibility mode when running PHP8 +- You can now use `$smarty->muteUndefinedOrNullWarnings()` to activate convert warnings about undefined or null template vars to notices when running PHP8 ### Changed - Switch CI from Travis to Github CI diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 9108189c..59dd3bca 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -644,7 +644,7 @@ class Smarty extends Smarty_Internal_TemplateBase * PHP7 Compatibility mode * @var bool */ - private $php7CompatMode = false; + private $isMutingUndefinedOrNullWarnings = false; /** * Initialize new Smarty object @@ -1382,16 +1382,16 @@ class Smarty extends Smarty_Internal_TemplateBase * * @void */ - public function setPHP7CompatMode(): void { - $this->php7CompatMode = true; + public function muteUndefinedOrNullWarnings(): void { + $this->isMutingUndefinedOrNullWarnings = true; } /** * Indicates if PHP7 compatibility mode is set. * @bool */ - public function getPHP7CompatMode(): bool { - return $this->php7CompatMode; + public function isMutingUndefinedOrNullWarnings(): bool { + return $this->isMutingUndefinedOrNullWarnings; } } diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 06fa965c..2ffb896f 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -200,7 +200,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data $_smarty_old_error_level = isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null; - if ($smarty->getPHP7CompatMode()) { + if ($smarty->isMutingUndefinedOrNullWarnings()) { $errorHandler = new Smarty_Internal_ErrorHandler(); $errorHandler->activate(); } diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php index 090fcb47..3e813100 100644 --- a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -89,14 +89,14 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty public function testUndefinedSimpleVar() { $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); - $this->smarty->setPHP7CompatMode(); + $this->smarty->muteUndefinedOrNullWarnings(); $tpl = $this->smarty->createTemplate('string:a{if $undef}def{/if}b'); $this->assertEquals("ab", $this->smarty->fetch($tpl)); } public function testUndefinedArrayIndex() { $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); - $this->smarty->setPHP7CompatMode(); + $this->smarty->muteUndefinedOrNullWarnings(); $tpl = $this->smarty->createTemplate('string:a{if $ar.undef}def{/if}b'); $tpl->assign('ar', []); $this->assertEquals("ab", $this->smarty->fetch($tpl)); @@ -104,7 +104,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty public function testUndefinedArrayIndexDeep() { $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); - $this->smarty->setPHP7CompatMode(); + $this->smarty->muteUndefinedOrNullWarnings(); $tpl = $this->smarty->createTemplate('string:a{if $ar.undef.nope.neither}def{/if}b'); $tpl->assign('ar', []); $this->assertEquals("ab", $this->smarty->fetch($tpl)); diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php index e388c5e7..12aed25d 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php @@ -285,7 +285,7 @@ class PluginFunctionHtmlCheckboxesTest extends PHPUnit_Smarty $this->_errors = array(); set_error_handler(array($this, 'error_handler')); - $this->smarty->setPHP7CompatMode(); + $this->smarty->muteUndefinedOrNullWarnings(); $tpl = $this->smarty->createTemplate('eval:{html_checkboxes name="id" options=$cust_radios selected=$customer_id separator="
"}'); $tpl->assign('customer_id', new _object_noString(1001)); $tpl->assign('cust_radios', array(