PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents

Home Page:https://phpoffice.github.io/PHPWord/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

idem84 opened this issue · comments

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

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.

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.

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.

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.

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?

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