Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true.

This commit is contained in:
Simon Wisselink
2023-01-12 09:59:10 +01:00
parent 577f910e49
commit 536721d457
2 changed files with 4 additions and 28 deletions

View File

@@ -4,21 +4,10 @@ namespace Smarty;
/**
* Smarty error handler to fix new error levels in PHP8 for backwards compatibility
*
* @author Simon Wisselink
*
*/
class ErrorHandler
{
/**
* Allows {$foo} where foo is unset.
* @var bool
*/
public $allowUndefinedVars = true;
/**
* Allows {$foo.bar} where bar is unset and {$foo.bar1.bar2} where either bar1 or bar2 is unset.
* @var bool
@@ -74,14 +63,6 @@ class ErrorHandler
*/
public function handleError($errno, $errstr, $errfile, $errline, $errcontext = [])
{
if ($this->allowUndefinedVars && preg_match(
'/^(Attempt to read property "value" on null|Trying to get property (\'value\' )?of non-object)/',
$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

View File

@@ -65,6 +65,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
*/
public function testError()
{
$this->smarty->error_unassigned = true;
$this->expectException(PHPUnit\Framework\Error\Error::class);
$this->expectExceptionMessage('Undefined ');
$e1 = error_reporting();
@@ -131,9 +132,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
$this->assertEquals("ab", $this->smarty->fetch($tpl));
}
/**
* @group 20221124
*/
public function testDereferenceOnNull() {
$this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE);
$this->smarty->muteUndefinedOrNullWarnings();
@@ -142,9 +141,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
$this->assertEquals("ab", $this->smarty->fetch($tpl));
}
/**
* @group 20221124
*/
public function testDereferenceOnBool() {
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
$this->smarty->muteUndefinedOrNullWarnings();
@@ -153,9 +150,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
$this->assertEquals("ab", $this->smarty->fetch($tpl));
}
/**
* @group 20221124
*/
public function testDereferenceOnString() {
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
$this->smarty->muteUndefinedOrNullWarnings();