Skip to content

Commit

Permalink
Rename setPHP7CompatMode/getPHP7CompatMode for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
wisskid committed Aug 18, 2021
1 parent c5cc763 commit 867154c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1382,16 +1382,16 @@ private function _normalizeTemplateConfig($isConfig)
*
* @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;
}

}
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_templatebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private function _execute($template, $cache_id, $compile_id, $parent, $function)
$_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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ public function testError()

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

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function testObjectNoString()
$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(
Expand Down

1 comment on commit 867154c

@glensc
Copy link
Contributor

@glensc glensc commented on 867154c Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clickbait title:

  • Rename setPHP7CompatMode/getPHP7CompatMode for clarity

not that much clickbait:

  • Rename setPHP7CompatMode/getPHP7CompatMode to muteUndefinedOrNullWarnings for clarity

rationale: the first title requires you to click to see the diff to even understand what the change is about. the second one, not that much.

Please sign in to comment.