mirror of
https://github.com/smarty-php/smarty.git
synced 2025-09-26 04:10: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]
|
## [Unreleased]
|
||||||
|
|
||||||
### Added
|
### 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
|
### Changed
|
||||||
- Switch CI from Travis to Github CI
|
- Switch CI from Travis to Github CI
|
||||||
|
@@ -644,7 +644,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
* PHP7 Compatibility mode
|
* PHP7 Compatibility mode
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $php7CompatMode = false;
|
private $isMutingUndefinedOrNullWarnings = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize new Smarty object
|
* Initialize new Smarty object
|
||||||
@@ -1382,16 +1382,16 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
*
|
*
|
||||||
* @void
|
* @void
|
||||||
*/
|
*/
|
||||||
public function setPHP7CompatMode(): void {
|
public function muteUndefinedOrNullWarnings(): void {
|
||||||
$this->php7CompatMode = true;
|
$this->isMutingUndefinedOrNullWarnings = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if PHP7 compatibility mode is set.
|
* Indicates if PHP7 compatibility mode is set.
|
||||||
* @bool
|
* @bool
|
||||||
*/
|
*/
|
||||||
public function getPHP7CompatMode(): bool {
|
public function isMutingUndefinedOrNullWarnings(): bool {
|
||||||
return $this->php7CompatMode;
|
return $this->isMutingUndefinedOrNullWarnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -200,7 +200,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
$_smarty_old_error_level =
|
$_smarty_old_error_level =
|
||||||
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
|
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
|
||||||
|
|
||||||
if ($smarty->getPHP7CompatMode()) {
|
if ($smarty->isMutingUndefinedOrNullWarnings()) {
|
||||||
$errorHandler = new Smarty_Internal_ErrorHandler();
|
$errorHandler = new Smarty_Internal_ErrorHandler();
|
||||||
$errorHandler->activate();
|
$errorHandler->activate();
|
||||||
}
|
}
|
||||||
|
@@ -89,14 +89,14 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
public function testUndefinedSimpleVar() {
|
public function testUndefinedSimpleVar() {
|
||||||
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||||
$this->smarty->setPHP7CompatMode();
|
$this->smarty->muteUndefinedOrNullWarnings();
|
||||||
$tpl = $this->smarty->createTemplate('string:a{if $undef}def{/if}b');
|
$tpl = $this->smarty->createTemplate('string:a{if $undef}def{/if}b');
|
||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUndefinedArrayIndex() {
|
public function testUndefinedArrayIndex() {
|
||||||
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
$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 = $this->smarty->createTemplate('string:a{if $ar.undef}def{/if}b');
|
||||||
$tpl->assign('ar', []);
|
$tpl->assign('ar', []);
|
||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||||
@@ -104,7 +104,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
public function testUndefinedArrayIndexDeep() {
|
public function testUndefinedArrayIndexDeep() {
|
||||||
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
$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 = $this->smarty->createTemplate('string:a{if $ar.undef.nope.neither}def{/if}b');
|
||||||
$tpl->assign('ar', []);
|
$tpl->assign('ar', []);
|
||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||||
|
@@ -285,7 +285,7 @@ class PluginFunctionHtmlCheckboxesTest extends PHPUnit_Smarty
|
|||||||
$this->_errors = array();
|
$this->_errors = array();
|
||||||
set_error_handler(array($this, 'error_handler'));
|
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 = $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('customer_id', new _object_noString(1001));
|
||||||
$tpl->assign('cust_radios', array(
|
$tpl->assign('cust_radios', array(
|
||||||
|
Reference in New Issue
Block a user