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

ZipStream\ZipStream::__construct(): Argument #1 ($comment) must be of type string, null given, called in \vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Writer\ZipStream2.php on line 19 #3615

Open
8 tasks
TwanaAssad opened this issue Jun 15, 2023 · 17 comments

Comments

@TwanaAssad
Copy link

This is:

- [

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Which versions of PhpSpreadsheet and PHP are affected?

@maennchen
Copy link

@TwanaAssad Is it possible that you have both ZipStream v2 and v3 installed at the same time?

If I had to guess, ZipStream\Option\Archive (from v2) exists and ZipStream\ZipStream resolves to v3 where comment is the argument in position 1.

Try cleanly reinstalling all your dependencies.

@bitterfountain
Copy link

I have the same problem in Laravel, I tried:

composer clear-cache
composer install
But still same problem, the PhpSpreadsheet stopped working totally, it's a disaster for my proyect...

@bitterfountain
Copy link

bitterfountain commented Jun 17, 2023

I found a bad solution but I needed urgently, changing vendor class:
file:
ZipStream0.php

Code:

namespace PhpOffice\PhpSpreadsheet\Writer;

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

class ZipStream0
{
    /**
     * @param resource $fileHandle
     */
    public static function newZipStream($fileHandle): ZipStream
    {
        /* the problem is in ZipStream2
        return class_exists(Archive::class) ? ZipStream2::newZipStream($fileHandle) : ZipStream3::newZipStream($fileHandle);
        */
        return ZipStream3::newZipStream($fileHandle);
    }
}

@oleibman
Copy link
Collaborator

If you have ZipStream2 installed, Archive::class should exist. If you have ZipStream3 installed, Archive::class should not exist. From your description, it sounds like you have ZipStream3 but also have Archive::class. So let's try to verify that to start.

Question 1 - Does directory vendor/maennchen/zipstream-php/src/Option/Archive exist on your system?

Question 2 - Does vendor/maennchen/zipstream-php/src/ZipStream.php have code that looks like:

public function __construct(?string $name = null, ?ArchiveOptions $opt = null)

Or does it look like:

    public function __construct(
        private OperationMode $operationMode = OperationMode::NORMAL,
        private readonly string $comment = '',
        $outputStream = null,
        private readonly CompressionMethod $defaultCompressionMethod = CompressionMethod::DEFLATE,
        private readonly int $defaultDeflateLevel = 6,
        private readonly bool $enableZip64 = true,
        private readonly bool $defaultEnableZeroHeader = true,
        private bool $sendHttpHeaders = true,
        ?Closure $httpHeaderCallback = null,
        private readonly ?string $outputName = null,
        private readonly string $contentDisposition = 'attachment',
        private readonly string $contentType = 'application/x-zip',
        private bool $flushOutput = false,
    ) {

@bitterfountain
Copy link

bitterfountain commented Jun 17, 2023

Question 1:
vendor/maennchen/zipstream-php/src/Option/Archive
Do not exist in my vendor

Question 2:
Yes, code it's similar to the second you said:

public function __construct(
        private readonly string $comment = '',
        $outputStream = null,
        private readonly CompressionMethod $defaultCompressionMethod = CompressionMethod::DEFLATE,
        private readonly int $defaultDeflateLevel = 6,
        private readonly bool $enableZip64 = true,
        private readonly bool $defaultEnableZeroHeader = true,
        private bool $sendHttpHeaders = true,
        ?Closure $httpHeaderCallback = null,
        private readonly ?string $outputName = null,
        private readonly string $contentDisposition = 'attachment',
        private readonly string $contentType = 'application/x-zip',
        private bool $flushOutput = false,
    ) {
        $this->outputStream = self::normalizeStream($outputStream);
        $this->httpHeaderCallback = $httpHeaderCallback ?? header(...);
    }

@daveaki
Copy link

daveaki commented Jun 17, 2023

I had the same problem with Codeigniter on Ubuntu server.
I solved this way.
I removed Spreadsheet with Composer.
I cleared the cache with Composer.
I deleted all the vendor folder.
I installed Spreadsheet with composer.
I uploaded all new vendor folder.
it worked.

Php 8.2 CI 4.3.5

I hope it can help

@bitterfountain
Copy link

THX daveaki!
It worked perfectly!

@oleibman
Copy link
Collaborator

Thank you @daveaki for helping to unravel this mystery.

@deloz
Copy link

deloz commented Jul 5, 2023

@daveaki thanks, you helped me .

@lekoala
Copy link

lekoala commented Jul 5, 2023

recent versions of zipstream require an operation mode as first argument

public function __construct(
private OperationMode $operationMode = OperationMode::NORMAL,

before it was

public function __construct(?string $name = null, ?ArchiveOptions $opt = null)
{

so i guess that's the issue

@danzisky
Copy link

Thanks so much @deloz , I also had the same issue and your steps worked. php 8.0.2

@DaDummy
Copy link

DaDummy commented Aug 15, 2023

Adding this dependency to my composer.json did workaround the issue:

		"maennchen/zipstream-php": "3.0.*",

I guess the quick fix for this issue is to just adjust the dependency version of maennchen/zipstream-php in this repository in a similar fashion since minor version updates of that dependency seemingly are not backwards compatible.

@DaDummy
Copy link

DaDummy commented Aug 15, 2023

For php 8.2 compatibility it appears

		"myclabs/php-enum": "^1.8",

also needs to be added.

@maennchen
Copy link

@DaDummy ZipStream v3 uses native enumns and does not need any dependencies.

Also the guarantee of stability in function arguments is only on named arguments, not the order since there are so many.

@nbtafelberg
Copy link

Adding this dependency to my composer.json did workaround the issue:

		"maennchen/zipstream-php": "3.0.*",

I guess the quick fix for this issue is to just adjust the dependency version of maennchen/zipstream-php in this repository in a similar fashion since minor version updates of that dependency seemingly are not backwards compatible.

This solved it for me thank you :-)

@hubtraum
Copy link

Another case for this error is if any other part of your code is requiring zipstream in version 2. In my case, I am using this library in a wordpress plugin. However, another wordpress plugin is using zipstream 2 which resulted in this error (zipstream2 being used instead of zipstream3).

@p3x-robot
Copy link

i fixed by require-ing from v3 to v2 and now with zipstream 2 is working now.

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