mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
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:
@@ -4,21 +4,10 @@ namespace Smarty;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty error handler to fix new error levels in PHP8 for backwards compatibility
|
* Smarty error handler to fix new error levels in PHP8 for backwards compatibility
|
||||||
*
|
|
||||||
|
|
||||||
|
|
||||||
* @author Simon Wisselink
|
* @author Simon Wisselink
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class ErrorHandler
|
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.
|
* Allows {$foo.bar} where bar is unset and {$foo.bar1.bar2} where either bar1 or bar2 is unset.
|
||||||
* @var bool
|
* @var bool
|
||||||
@@ -74,14 +63,6 @@ class ErrorHandler
|
|||||||
*/
|
*/
|
||||||
public function handleError($errno, $errstr, $errfile, $errline, $errcontext = [])
|
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(
|
if ($this->allowUndefinedArrayKeys && preg_match(
|
||||||
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type)/',
|
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type)/',
|
||||||
$errstr
|
$errstr
|
||||||
|
@@ -65,6 +65,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testError()
|
public function testError()
|
||||||
{
|
{
|
||||||
|
$this->smarty->error_unassigned = true;
|
||||||
$this->expectException(PHPUnit\Framework\Error\Error::class);
|
$this->expectException(PHPUnit\Framework\Error\Error::class);
|
||||||
$this->expectExceptionMessage('Undefined ');
|
$this->expectExceptionMessage('Undefined ');
|
||||||
$e1 = error_reporting();
|
$e1 = error_reporting();
|
||||||
@@ -131,9 +132,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group 20221124
|
|
||||||
*/
|
|
||||||
public function testDereferenceOnNull() {
|
public function testDereferenceOnNull() {
|
||||||
$this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE);
|
$this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE);
|
||||||
$this->smarty->muteUndefinedOrNullWarnings();
|
$this->smarty->muteUndefinedOrNullWarnings();
|
||||||
@@ -142,9 +141,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group 20221124
|
|
||||||
*/
|
|
||||||
public function testDereferenceOnBool() {
|
public function testDereferenceOnBool() {
|
||||||
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||||
$this->smarty->muteUndefinedOrNullWarnings();
|
$this->smarty->muteUndefinedOrNullWarnings();
|
||||||
@@ -153,9 +150,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group 20221124
|
|
||||||
*/
|
|
||||||
public function testDereferenceOnString() {
|
public function testDereferenceOnString() {
|
||||||
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||||
$this->smarty->muteUndefinedOrNullWarnings();
|
$this->smarty->muteUndefinedOrNullWarnings();
|
||||||
|
Reference in New Issue
Block a user