Skip to content

Commit

Permalink
muteUndefinedOrNullWarnings() now also mutes PHP8 warnings for undefi…
Browse files Browse the repository at this point in the history
…ned properties (#891)
  • Loading branch information
wisskid authored Jul 19, 2023
1 parent 19df91b commit 4434e12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- `$smarty->muteUndefinedOrNullWarnings()` now also mutes PHP8 warnings for undefined properties

## [4.3.1] - 2023-03-28

### Security
Expand Down
13 changes: 13 additions & 0 deletions libs/sysplugins/smarty_internal_errorhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class Smarty_Internal_ErrorHandler
*/
public $allowUndefinedVars = true;

/**
* Allows {$foo->propName} where propName is undefined.
* @var bool
*/
public $allowUndefinedProperties = true;

/**
* Allows {$foo.bar} where bar is unset and {$foo.bar1.bar2} where either bar1 or bar2 is unset.
* @var bool
Expand Down Expand Up @@ -80,6 +86,13 @@ public function handleError($errno, $errstr, $errfile, $errline, $errcontext = [
return; // suppresses this error
}

if ($this->allowUndefinedProperties && preg_match(
'/^(Undefined property)/',
$errstr
)) {
return; // suppresses this error
}

if ($this->allowUndefinedArrayKeys && preg_match(
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type)/',
$errstr
Expand Down

0 comments on commit 4434e12

Please sign in to comment.