2

I'd like to use the PclZip lib in a Magento module. I installed it through my package manager (libphp-pclzip) but I'm not able to use it directly in my module, the Magento autoloader tries to get the class and fails:

Warning: include(PclZip.php): failed to open stream: No such file or directory in /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php on line 93

#0 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'include(PclZip....', '/home/frleq/Dev...', 93, Array)
#1 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('PclZip')
#3 [internal function]: spl_autoload_call('PclZip')
#4 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/app/code/community/Compario/Connector/Helper/Data.php(8): class_exists('PclZip')

How can I manage to disable the autoload or make it find my lib?

Thanks!

frinux
  • 2,052
  • 6
  • 26
  • 47

2 Answers2

3

The quick solution is to add directory with your library to include path:

$includePath = 'path/to/lib';
set_include_path(get_include_path() . PS . $includePath);

One more quick solution:

require_once  'path/to/lib/PclZip.php';

But better solution is to change the name of your lib to be visible to autoloader. It should be inside lib directory, the name of class should consists of words which starts from capital letter and separated by "_". These words should match directory structure of file with class. For example:

'path/to/lib/PclZip.php' => Path_To_Lib_PclZip'
Eugene Tulika
  • 703
  • 5
  • 11
  • Impossible to change the name of the lib, it is external, installed through package manager and I want a generic solution. – frinux Jan 18 '11 at 15:51
  • see this answer: http://stackoverflow.com/questions/6417394/how-to-add-a-3rd-party-library-to-magento#answer-22899482 – Mohamed23gharbi Apr 29 '16 at 14:51
1

See this answer for some ideas on setting up a custom autoloader in Magento that won't conflict with the built in.

Community
  • 1
  • 1
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • It is an elegant solution, but far too much heavy! I do not want to create a custom autoloader for a such little functionnality. The final aim is to propose an archive if PclZip is installed, but I can skip ths step. So I won't create a custom autoloader just for this. Thanks anyway ;) – frinux Jan 18 '11 at 15:53