Describe the bug
The AbstractTextViewHelper throws PHP 8 errors if text is empty and trim or removeDoubleWhitespace is set to 1. This happens with the ListViewHelper that has the AbstractTextViewHelper as parent.
PHP Runtime Deprecation Notice: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /.../typo3conf/ext/pdfviewhelpers/Classes/ViewHelpers/AbstractTextViewHelper.php line 111
or
PHP Runtime Deprecation Notice: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /.../typo3conf/ext/pdfviewhelpers/Classes/ViewHelpers/AbstractTextViewHelper.php line 115
Possible solution
The problem lies in the initialize function of the AbstractTextViewHelper class with the following statements:
if ($this->arguments['trim']) {
$this->arguments['text'] = trim($this->arguments['text']);
}
if ($this->arguments['removeDoubleWhitespace']) {
$this->arguments['text'] = preg_replace('/[ \t]+/', ' ', $this->arguments['text']);
}
Here text is null triggering the PHP 8 deprecation. Adding && !empty($this->arguments['text'] to both if statements should fix the problem.
Both trim and removeDoubleWhitespace are set to 1 per TypoScript settings of generalText per default. As workaround I have set both configs to 0 for list. This is a general problem though and should be fixed.
Describe the bug The
AbstractTextViewHelper
throws PHP 8 errors iftext
is empty andtrim
orremoveDoubleWhitespace
is set to 1. This happens with theListViewHelper
that has theAbstractTextViewHelper
as parent.Environment TYPO3 version(s): 11.5 PHP: 8.2 pdfviewhelpers version: 2.5.0
Steps to reproduce Add a list to the pdf like this:
Expected behavior The list is rendered
Actual behavior
PHP Exception:
or
Possible solution
The problem lies in the
initialize
function of theAbstractTextViewHelper
class with the following statements:Here
text
is null triggering the PHP 8 deprecation. Adding&& !empty($this->arguments['text']
to both if statements should fix the problem.Both
trim
andremoveDoubleWhitespace
are set to 1 per TypoScript settings ofgeneralText
per default. As workaround I have set both configs to 0 forlist
. This is a general problem though and should be fixed.