3

I tried this code

var_dump(class_exists('ZipArchive'));
$zip = new ZipArchive();

well, the output is like this.

bool(true)
Fatal error: Class 'MyProject\ProjectBundle\Controller\ZipArchive' not found in \path\to\my\Controller.php on line 83

Anyone can help me how to solve this? I have installed

php-pear
php5-dev
libcurl3-openssl-dev
libevent-dev
pecl-http
all i need have been installed
and i have put the extension to my php.ini then restart my apache

But i still get that error. Then I tried this

$z = new /ZipArchive();

from this page

and then i got this error :

Parse error: syntax error, unexpected '/' in /path/to/my/symfonyController.php on line 83
Sherly Febrianti
  • 1,097
  • 15
  • 33
  • Where did you save your class? It doesn't look like you saved it in the right place – Rafael Jan 29 '15 at 03:37
  • umm, i have found the answer.. Adding `use ZipArchive` after the namespace.. and then `$z = new ZipArchive();` – Sherly Febrianti Jan 29 '15 at 03:41
  • 2
    Just calling `new ZipArchive()` looks for a class `ZipArchive` in the local directory. You had the right idea with the `new /ZipArchive()` except that **you have the slash the wrong way around**, you should actually be using `new \ZipArchive()` (the slash takes it to the global namespace). – qooplmao Jan 29 '15 at 10:15
  • Thanks for your comment.. I have try that too, but it doesnt work.. Umm, but now i have found the way and it works.. – Sherly Febrianti Jan 30 '15 at 03:17

2 Answers2

12

After installation is done and check your ZipArchive class is exist with this code

var_dump(class_exists('ZipArchive'));

if it returns true then you just add

use ZipArchive;

put it after your namespace
and then put this code

$zip = new ZipArchive();

on where you are want to put.

Sherly Febrianti
  • 1,097
  • 15
  • 33
2

You need to refer to ziparchive and then use the call $Z. To refer you have to add use ZipArchive before the new line

user 12321
  • 2,846
  • 1
  • 24
  • 34