FluidTYPO3 / vhs

TYPO3 extension VHS: Fluid ViewHelpers
https://fluidtypo3.org
Other
189 stars 228 forks source link

PHP 8 warning exception due to missing array keys: Undefined array key "forceClosingTag" #1793

Closed taherbensassi closed 1 year ago

taherbensassi commented 2 years ago

PHP: 8.1.5 TYPO3: 11.5.12 VHS: 6.1.2

After installing TYPO3 and VHS, I got this error.

NamelessCoder commented 1 year ago

Is this still occurring with the current development branch and if so, can you provide a stack trace?

Oktopuce commented 1 year ago

I confirm the bug even with the development branch, the bug appears when using the ViewHelper :

<v:page.header.link rel="next" href="/" />

TYPO3: 11.5.21 PHP: 8.0.26 VHS: 6.1.2

(1/1) #1476107295 TYPO3\CMS\Core\Error\Exception

PHP Warning: Undefined array key "forceClosingTag" in /var/www/html/web/typo3conf/ext/vhs/Classes/Traits/TagViewHelperTrait.php line 117 in /var/www/html/web/typo3/sysext/core/Classes/Error/ErrorHandler.php line 137

    }

    $message = self::ERROR_LEVEL_LABELS[$errorLevel] . ': ' . $errorMessage . ' in ' . $errorFile . ' line ' . $errorLine;
    if ($errorLevel & $this->exceptionalErrors) {
        throw new Exception($message, 1476107295);
    }

    $message = $this->getFormattedLogMessage($message);
Oktopuce commented 1 year ago

The problem is with all the $this->arguments in TagViewHelperTrait.php method renderTag() because with PHP V8 all undefined array lead to a warning.

A quick fix is to check if the array key exist and set a default value like this: $forceClosingTag = (boolean) ($this->arguments['forceClosingTag'] ?? false);