3

I am attempting to create an encrypted, password protected ZIP file using PHP 7.2.7. However, I am getting the following error message:

Attempted to call an undefined method named "setEncryptionName" of class "ZipArchive".

http://php.net/manual/en/ziparchive.setencryptionname.php

If I remove $zip->setEncryptionName() then everything works 100%, except that the ZIP file is then not password protected.

I have done a Google & Forum search and cannot find anybody that has experienced a similar problem, probably because the PHP version and functionality is still so new.

Magnanimity
  • 1,293
  • 8
  • 24
  • 44
  • 2
    First thing that pops to mind is that you're not using PHP 7.2 but an earlier version. In the same .php file, can you verify that you're on 7.2 by adding `echo phpversion();`? Let's get that out of the way before proceeding further. – N.B. Jul 06 '18 at 13:14
  • `echo phpversion();` returns `7.2.7` – Magnanimity Jul 06 '18 at 13:19
  • 1
    And PECL version should be above 1.14.0 according to the docs. You can probably check that in `phpinfo()` – Loek Jul 06 '18 at 13:21
  • `phpinfo()` does not show any information pertaining to PECL. I will have to contact my hosting provider for this. – Magnanimity Jul 06 '18 at 13:26
  • 2
    Manual states that the method is there, your PHP says it's not there. You could use `Reflection` to inspect your `$zip` object using `$reflection = new ReflectionClass($zip); print_r($reflection->getMethods());` and see what's available. – N.B. Jul 06 '18 at 13:49
  • Any update on this? I am also experiencing this issue... – Ng Sek Long Oct 15 '18 at 03:47

1 Answers1

6

For the ZipArchive::setEncryptionName method to work You will need PHP >= 7.2 With the ZIP extension.

Note the the ZIP extension needs to be compiled with libzip-dev >= 1.2.0

A common issue in many pre-compiled packages is that the compiler did not upgrade libzip-dev before compiling the php-zip extension. Which is probably your case.

Be aware that your ZIPs will not be encrypted and that the setPassword() function is only used to extract zips if ZipArchive::setEncryptionName is not available.

Here is the changelog: http://pecl.php.net/package-info.php?package=zip&version=1.14.0

dehart
  • 1,554
  • 15
  • 18
  • I'm getting this too - PHP 7.2.19 with libzip 1.1.2. My solution will be to build the right combination of things in Docker, so it isn't susceptible to flaky distro dependencies. – halfer Aug 25 '19 at 13:22