Skip to content

PHP 7.4 fatal parse error in setasign/fpdi: unexpected '{', expecting variable... #260

Description

@salvoyith

On a PHP 7.4 environment, generating a PDF fails with a fatal parse error coming from setasign/fpdi:
During class fetch: Uncaught ParseError: syntax error, unexpected '{', expecting variable (T_VARIABLE)
The error points to:
/setasign/fpdi/src/FpdiTrait.php:117

Error details
The failing code is:

protected function getPdfParserInstance(StreamReader $streamReader, #[\SensitiveParameter] array $parserParams = [])

mPDF version

^8.2.5

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

7.4

Reproducible PHP+CSS+HTML snippet suffering by the error

Steps to reproduce

Use a PHP 7.4 environment
Install the package(s) via Composer
Trigger PDF generation so that FPDI is loaded
The application crashes with the parse error above
Expected behavior
The package set should remain compatible with PHP 7.4, or Composer should not resolve/install a version that contains syntax unsupported by PHP 7.4.

Actual behavior

A fatal parse error is thrown when setasign/fpdi is loaded.

Additional notes

According to the package constraints, this version appears to allow PHP 7.4, but the shipped code contains PHP attribute syntax that is not parseable on PHP 7.4.

As a temporary workaround, pinning setasign/fpdi to 2.6.4 avoids the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions