Skip to content

Deprecation on PHP 8.1 in ZipArchive #2187

Closed
@garethellis36

Description

@garethellis36
Deprecated: ZipArchive::open(): Passing null to parameter #2 ($flags) of type int is deprecated in /var/itrans/one/app/Vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php on line 136

The current method signature of ZipArchive::open() is public function open($filename, $flags = null).

If no argument is passed as the second argument here, null is passed as the second argument on line 136:

            $zip = new \ZipArchive();
            $result = $zip->open($this->filename, $flags); // <-- line 136

Passing 0 achieves the same behaviour as passing null. Therefore, I believe the appropriate fix here would be:

$zip = new \ZipArchive();

if ($flags === null) {
 $flags = 0;
}

$result = $zip->open($this->filename, $flags);

This would eliminate the deprecation and not break any BC within the library.

I'm happy to submit a PR if required.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions