From: Roland Häder Date: Fri, 22 Aug 2025 02:12:25 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9496ed5ba8260bded9c81245921653d02d7b3ffa;p=core.git Continued: - getVariableIndex() does never return false, but -1 if $variableName was not found --- diff --git a/framework/main/classes/template/class_BaseTemplateEngine.php b/framework/main/classes/template/class_BaseTemplateEngine.php index cf27c1b3..bef77160 100644 --- a/framework/main/classes/template/class_BaseTemplateEngine.php +++ b/framework/main/classes/template/class_BaseTemplateEngine.php @@ -351,7 +351,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { // Is the variable found? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-TEMPLATE: found[]=%s', gettype($found))); - if ($found !== false) { + if ($found > -1) { // Read it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-TEMPLATE: Invoking this->getVariableValue(%s,%s) ...', $variableGroup, $found)); $value = $this->getVariableValue($variableGroup, $found); @@ -506,6 +506,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { // Get index for variable /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-TEMPLATE: this->getVariableIndex(%s) ...', $variableName)); $index = $this->getVariableIndex($variableName); + assert($index >= 0, sprintf('variableName=%s not found', $variableName)); // Then modify it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-TEMPLATE: this->setVariableValue(%s,%d,value[]=%s) ...', $this->currGroup, $index, gettype($value))); @@ -562,8 +563,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { $index = $this->getVariableIndex($variableName); // Is the variable set? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-TEMPLATE: index[]=%s', gettype($index))); - if ($index === false) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-TEMPLATE: index[%s]=%d', gettype($index), $index)); + if ($index === -1) { // Is the stack there? if (!isset($this->varStack[$variableGroup])) { // Then initialize it here @@ -1009,7 +1010,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) { // Template not found, but maybe variable assigned? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-TEMPLATE: template=%s not loaded yet', $template)); - if ($this->getVariableIndex($template) !== false) { + if ($this->getVariableIndex($template) > -1) { // Use that content here /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-TEMPLATE: Assigning this->loadedTemplateData[%s] from variable template=%s ...', $template, $template)); $this->loadedRawData[$template] = $this->readVariable($template); @@ -1326,7 +1327,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { $index = $this->getVariableIndex($variableName); // Was it found? - if ($index === false) { + if ($index === -1) { // Add it to the stack //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:ADD: ' . $variableName . '[' . gettype($value) . ']=' . $value); $this->addVariable($variableName, $value); @@ -1359,7 +1360,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { $index = $this->getVariableIndex($variableName, $variableGroup); // Was it found? - if ($index !== false) { + if ($index > -1) { // Remove this variable //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:UNSET: variableGroup=' . $variableGroup . ',variableName=' . $variableName . ',index=' . $index); $this->unsetVariableStackOffset($index, $variableGroup);