bithost-gmbh / pdfviewhelpers

TYPO3 CMS extension that provides various Fluid ViewHelpers to generate PDF documents.
GNU General Public License v3.0
44 stars 19 forks source link

PHP 8 error in ColumnViewHelper if width isn't set #223

Closed rk-mxp closed 1 year ago

rk-mxp commented 1 year ago

Describe the bug When using the ColumnViewHelper without width the following PHP error occurs with PHP 8:

PHP Runtime Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /.../typo3conf/ext/pdfviewhelpers/Classes/ViewHelpers/ColumnViewHelper.php line 65

Environment TYPO3 version(s): 11.5 PHP Version: 8.2 pdfviewhelpers version: 2.5.0

Steps to reproduce Add a ColumnViewHelper to the PDF like this:

<pdf:multiColumn>
<pdf:column>
    <pdf:list listElements="{
    0: 'Option 1',
    1: 'Option 2',
    2: 'Option 3'
}" />
</pdf:column>
<pdf:column>
    <pdf:list listElements="{
    0: 'Option 4',
    1: 'Option 5',
    2: 'Option 6'
}" />
</pdf:column>
</pdf:multiColumn>

Expected behavior The columns are rendered

Possible solution The problem is the if in the initialize function of the ColumnViewHelper:

if (strlen($this->arguments['width'])) {
    if ($this->validationService->validateWidth($this->arguments['width'])) {
        $multiColumnContext['columnWidth'] = $this->conversionService->convertSpeakingWidthToTcpdfWidth($this->arguments['width'], $multiColumnContext['pageWidthWithoutMargins']);
    }
} else {
    $multiColumnContext['columnWidth'] = $multiColumnContext['defaultColumnWidth'];
}

Replacing strlen with !empty as test function should fix the problem

maechler commented 1 year ago

@Barakur Thank you very much for the detailed error report! I'll have a look at it.

maechler commented 1 year ago

This should already be solved in the current main branch by casting the width to a string:

https://github.com/bithost-gmbh/pdfviewhelpers/blob/eefa422651df17489dd83dd6ae09ed83a27c664f/Classes/ViewHelpers/ColumnViewHelper.php#L67

The !empty approach would not be working for zero width, because empty('0') evaluates to true. I hope I'll soon have a release for this.