Skip to content

Incompatibility with PHP 7.4 due to str_starts_with usage in Drawing.php on PhpSpreadsheet v1.29.0 #4215

@gabox00

Description

@gabox00

This is:

less

What is the current behavior?
An error occurs due to the usage of str_starts_with, which is a PHP 8.0 function, in the Drawing.php file. This function is not compatible with PHP 7.4.

What are the steps to reproduce?

$spreadsheet = IOFactory::load($_FILES['fileSEPA']['tmp_name']);

Error location
The error is located in the vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/Drawing.php file, specifically in the isImage method:

private function isImage(string $path): bool
{
$mime = (string) @mime_content_type($path);
$retVal = false;
if (str_starts_with($mime, 'image/')) { // This line causes the error
$retVal = true;
} elseif ($mime === 'application/octet-stream') {
$extension = pathinfo($path, PATHINFO_EXTENSION);
$retVal = in_array($extension, ['bin', 'emf'], true);
}

return $retVal;

}

What features do you think are causing the issue
Reader
Writer
Styles
Data Validations
Formula Calculations
Charts
AutoFilter
Form Elements
Drawing (specifically)
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
N/A

Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet: 1.29.0
PHP: 7.4
Suggested Solution
Replace the str_starts_with function in Drawing.php with an alternative compatible with PHP 7.4, such as strpos($mime, 'image/') === 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions