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

close() function in destructor of Madzipper causes 'Invalid or uninitialized Zip object' with PHP 8 #21

Closed
ssbrandsma opened this issue Jun 18, 2021 · 8 comments

Comments

@ssbrandsma
Copy link

ssbrandsma commented Jun 18, 2021

Sample code to reproduce:

$zipper = new Madzipper;
$zipper->make($relativeFolder . $filenameZip)
               ->addString($filename, $qms_data)
               ->close();
$zipper = null; // close is also called via destructor of Madzipper

ZipRepository.php

    /**
     * Closes the archive and saves it
     */
    public function close()
    {
        @$this->archive->close();      //  <----  error surpressed 
    }

In PHP 8.0, the @ operator does not suppress certain types of errors that were silenced prior to PHP 8.0.

Until this is fixed, I don't call close() after adding the string but let de destructor close it.

@scs-ben
Copy link
Contributor

scs-ben commented Aug 30, 2021

Thank you for posting this workaround!

@smknstd
Copy link

smknstd commented Oct 20, 2021

Warning This function has been DEPRECATED as of PHP 8.0.0. Relying on this function is highly discouraged.

https://www.php.net/manual/fr/function.zip-close.php

@ggmanuilov
Copy link

I migrate application from php7.2 to php8 and get this problem.
After add this checking my tests work correnctly.

   /**
     * Closes the archive and saves it.
     */
    public function close()
    {
        $this->archive->filename and $this->archive->close();
    }

How do you think it correctly checking?

@theimerj
Copy link
Collaborator

Should be fixed in v1.2.1 and v1.3.1. Thank you for reporting.

@melikadze
Copy link

Its not fixed at all

@theimerj
Copy link
Collaborator

@melikadze can you open a PR with a proposed fix? I do not have time to look into that atm.

@sidneygijzen
Copy link

Just to confirm; unfortunately I also am running into the same error Uncaught ValueError: Invalid or uninitialized Zip object when trying to call close() on the zipfile. The app is running PHP 8.0.20. Applying the aforementioned workaround (in the first post) fixes the issue.

scs-ben added a commit to scs-ben/madzipper that referenced this issue Jul 27, 2022
Apparently, there are ways to close the Zip object when it's not expected to be closed. This would address madnest#21 and madnest#29
@scs-ben
Copy link
Contributor

scs-ben commented Jul 27, 2022

@theimerj I created a PR to address this by catching the error

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

No branches or pull requests

7 participants