mirror of
https://github.com/smarty-php/smarty.git
synced 2025-09-25 20:00:54 +02:00
Rename setPHP7CompatMode/getPHP7CompatMode for clarity
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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));
|
||||
|
@@ -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="<br />"}');
|
||||
$tpl->assign('customer_id', new _object_noString(1001));
|
||||
$tpl->assign('cust_radios', array(
|
||||
|
Reference in New Issue
Block a user