Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZipStream3 initialization issue #3619

Closed
absiddiqueLive opened this issue Jun 19, 2023 · 6 comments
Closed

ZipStream3 initialization issue #3619

absiddiqueLive opened this issue Jun 19, 2023 · 6 comments

Comments

@absiddiqueLive
Copy link

absiddiqueLive commented Jun 19, 2023

This is:

- A bug report

[2023-06-18 12:52:57] production.ERROR: syntax error, unexpected ':', expecting ')' {"exception":""Symfony\\Component\\Debug\\Exception\\FatalThrowableError: syntax error, unexpected ':', expecting ')' in \/data\/app\/hris-api\/vendor\/phpoffice\/phpspreadsheet\/src\/PhpSpreadsheet\/Writer\/ZipStream3.php:16
Stack trace:\

Facing the issue with php 7.4, Laravel 5.8 and PhpSpreadsheet 1.29.0

<?php

namespace PhpOffice\PhpSpreadsheet\Writer;

use ZipStream\Option\Archive;
use ZipStream\ZipStream;

class ZipStream3
{
    /**
     * @param resource $fileHandle
     */
    public static function newZipStream($fileHandle): ZipStream
    {
        return new ZipStream(
            enableZip64: false,
            outputStream: $fileHandle,
            sendHttpHeaders: false,
            defaultEnableZeroHeader: false, // the issue occurring due to the ending comma 
        );
    }
}
@maennchen
Copy link

Same as #3616 (comment) except that you need ^2.2 since >= 2.3.0 requires a higher PHP version.

If it is possible, I recommend updating to an actively maintained PHP version, which solves this as well.

@absiddiqueLive
Copy link
Author

absiddiqueLive commented Jun 19, 2023

Understood but composer.json said it support php7.4

"php": "^7.4 || ^8.0",

https://github.com/PHPOffice/PhpSpreadsheet/blob/master/composer.json

@MarkBaker
Copy link
Member

MarkBaker commented Jun 19, 2023

Understood but composer.json said it support php7.4

"php": "^7.4 || ^8.0",

PhpSpreadsheet does support PHP 7.4 (at least for the next few weeks). There is nothing in the PhpSpreadsheet that will fail if you are running PHP 7.4.

However:
composer.json indicates that you need maennchen/zipstream-php at version 2.1 or above

"maennchen/zipstream-php": "^2.1 || ^3.0"

but an install should only use version 3.0+ if you are running PHP 8.1 or above, only use version 2.2+ if you are running PHP 8.0.x. If you are running PHP 7.4.x, then version 2.1.x should be installed.

If you have forced the installation of zipstream-php > 2.1, then you will have problems with PHP 7.4

P.S.
PhpSpreadsheet 2.9.0 does not exist.

@MinKyawNyunt
Copy link

downgrading maennchen/zipstream-php to 2.1 fixed the issue on php version 7.4.

composer require maennchen/zipstream-php:^2.1

@oleibman
Copy link
Collaborator

Closing as duplicate of #3615 (if it is still a problem).

@lserni
Copy link

lserni commented Mar 26, 2024

A possible workaround if downgrading ZipStream is not possible is to modify phpoffice so that the call is more compatible:

`
// This is ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/ZipStream2.php

namespace PhpOffice\PhpSpreadsheet\Writer;

use ZipStream\Option\Archive;
use ZipStream\ZipStream;
use ZipStream\OperationMode;
use ZipStream\CompressionMethod;

class ZipStream2
{
/**
* @param resource $fileHandle
*/
public static function newZipStream($fileHandle): ZipStream
{
return new ZipStream(
OperationMode::NORMAL,
'',
$fileHandle,
CompressionMethod::DEFLATE,
6,
true,
true,
false
);
}
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants