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

Call of $this->zipClass->close() repeat twice #2548

Open
idem84 opened this issue Jan 11, 2024 · 6 comments
Open

Call of $this->zipClass->close() repeat twice #2548

idem84 opened this issue Jan 11, 2024 · 6 comments

Comments

@idem84
Copy link

idem84 commented Jan 11, 2024

Describe the Bug

Inside file TemplateProcessor.php in functions __destruct() and save() repeat code that close ZipArchive, and becouse of that error appears: ZipArchive::close() Invalid or unitialized Zip object

Steps to Reproduce

Please provide a code sample that reproduces the issue.

function __destruct() 
// ZipClass
        if ($this->zipClass) {
            try {
                $this->zipClass->close();
            } catch (Throwable $e) {
                // Nothing to do here.
            }
        }

function save()
// Close zip file
        if (false === $this->zipClass->close()) {
            throw new Exception('Could not close zip file.'); // @codeCoverageIgnore
        }

Expected Behavior

I think inside _destruct need to remove close() function

Context

Please fill in your environment information:

  • PHP Version: 7.4
  • PHPWord Version: Latest
@oleibman
Copy link
Contributor

What is the problem you are seeing? The close in the destructor is in a try-catch block, so I think it should just fail silently and harmlessly in your case; I don't see any error messages or any other problem when I run tests.

@oleibman
Copy link
Contributor

Hmm, I think I do see a warning message when I run under Php7.4. That is long out of support, but I'll investigate further.

@oleibman
Copy link
Contributor

This is very strange. I can reproduce the problem (for Php7) when running on its own. But I cannot reproduce it when running Phpunit tests with Php7, which is why this code passed all unit tests. I can fix it for Php7, but I can't formally prove that it's been fixed.

@oleibman
Copy link
Contributor

Less of a mystery now. Php seems to have changed this from a warning to a fatal error in Php8. So Php8 has no warning message to suppress, and, without an at-sign, Php7 has no reason to suppress a message.

oleibman added a commit to oleibman/PHPWord that referenced this issue Jan 18, 2024
Fix PHPOffice#2548. A particularly perplexing problem accidentally introduced by PR PHPOffice#2475. Problem does not arise for Php8, and does not arise for Php7 unit tests. But, running *not* under Phpunit auspices with Php7 can cause a warning message at destructor time if the `save` function has been used. A very artificial test is introduced to test this situation.
@ukasinn
Copy link

ukasinn commented Mar 20, 2024

I'm having the same problem with php 7.3
I replaced 【$this->zipClass->close();】with【@$this->zipClass->close();】
Will there be any other side effects?

@oleibman
Copy link
Contributor

@ukasinn I think your change will not have side effects. PR #2554 will be a more robust solution when it is merged.

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

No branches or pull requests

3 participants