From 9658953a78f0078078e05e12503c1d5e93777e5a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 9 Jun 2023 15:43:17 -0700 Subject: [PATCH] CRM_Core_Smarty - Fix restoration of undefined values (following temporary assignments) --- CRM/Core/Smarty.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index 769bb813ef..b5c22c62df 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -66,6 +66,16 @@ class CRM_Core_Smarty extends Smarty { */ private $backupFrames = []; + /** + * This is a sentinel-object that indicates an undefined value. + * + * It lacks any substantive content; but it has unique identity that cannot be mistaken for + * organic values like `null`, `string`, `false`, or similar. + * + * @var object + */ + private static $UNDEFINED_VALUE; + private function initialize() { $config = CRM_Core_Config::singleton(); @@ -161,6 +171,9 @@ class CRM_Core_Smarty extends Smarty { * @return \CRM_Core_Smarty */ public static function &singleton() { + if (static::$UNDEFINED_VALUE === NULL) { + static::$UNDEFINED_VALUE = new stdClass(); + } if (!isset(self::$_singleton)) { self::$_singleton = new CRM_Core_Smarty(); self::$_singleton->initialize(); @@ -346,7 +359,7 @@ class CRM_Core_Smarty extends Smarty { $oldVars = $this->get_template_vars(); $backupFrame = []; foreach ($vars as $key => $value) { - $backupFrame[$key] = $oldVars[$key] ?? NULL; + $backupFrame[$key] = array_key_exists($key, $oldVars) ? $oldVars[$key] : static::$UNDEFINED_VALUE; } $this->backupFrames[] = $backupFrame; @@ -373,7 +386,12 @@ class CRM_Core_Smarty extends Smarty { */ public function assignAll($vars) { foreach ($vars as $key => $value) { - $this->assign($key, $value); + if ($value !== static::$UNDEFINED_VALUE) { + $this->assign($key, $value); + } + else { + $this->clear_assign($key); + } } return $this; } -- 2.25.1