Clean install of PHPExcel 1.7.7: PHPExcel_Worksheet not found

Aug 6, 2012 at 3:26 PM

Hi all,

I've just installed PHPExcel 1.7.7 for testing purposes, but a fatal exception was thrown when trying the first example file (01simple.php):

15:22:29 Create new PHPExcel object
Fatal error: Class 'PHPExcel_Worksheet' not found in /public/sites/phpexcel.hbs-artemis.nl/Classes/PHPExcel.php on line 108

I've made no changes whatsoever to the code and both Classes and Tests directories are in the root of the subdomain (phpexcel.hbs-artemis.nl).

As far as I know, I match the requirements, tested with the following code, which returns OK for all extensions:

 echo "GD: ", extension_loaded('gd') ? 'OK' : 'MISSING', '<br>';
 echo "XML: ", extension_loaded('xml') ? 'OK' : 'MISSING', '<br>';
 echo "zip: ", extension_loaded('zip') ? 'OK' : 'MISSING', '<br>';

Is this a bug in 1.7.7, of a configuration error at my site?

Yours faithfully,

Roy van Lamoen

Coordinator
Aug 7, 2012 at 7:39 AM

This isn't normal behaviour, otherwise it would affect everybody including myself. PHPExcel uses an autoloader to include the files that it needs: Line 34 of 01simple.php includes the core PHPExcel class file, and the autoloader is loaded by the first few lines of code in that (lines 30-33) which set the directory path for the PHPExcel library, and require the autoloader file. The autoloader registers itself using the standard spl_autoload_register function, and also includes a couple of other PHPExcel library files that are being included correctly else your error would occur when it tries to autoload them.

Can you provide a call stack trace (would normally be displayed when the fatal error is thrown) to help try and diagnose why the autoloader is selectively loading some files and not others. thank you

Aug 7, 2012 at 8:47 AM
Edited Aug 7, 2012 at 9:55 AM

Unfortunately, I don't get a call stack trace (not on screen nor in error_log). Only the above mentioned fatal error is shown.

So I added some echo statement in de Autoloader Load function which output the loaded and not loaded files. Complete output is as follows:

Loading /public/sites/phpexcel.hbs-artemis.nl/Classes/PHPExcel/Shared/ZipStreamWrapper.php
Loading /public/sites/phpexcel.hbs-artemis.nl/Classes/PHPExcel/Shared/String.php
08:33:17 Create new PHPExcel object 
Loading /public/sites/phpexcel.hbs-artemis.nl/Classes/PHPExcel/Worksheet.php
Loading /public/sites/phpexcel.hbs-artemis.nl/Classes/PHPExcel/Writer/Excel5/BIFFwriter.php

Fatal error: Class 'PHPExcel_Worksheet' not found in /public/sites/phpexcel.hbs-artemis.nl/Classes/PHPExcel.php on line 108

The fatal error is thrown when the new PHPExcel object is created in 01simple.php on line 39. 

If you need more of this manual debug info, let me know!

Edit:
I've just tried v1.7.6 on a seperate subdomain (http://phpexcel176.hbs-artemis.nl) and this version seems to work for me. An update to 1.7.7 breaks PHPExcel again.

Aug 10, 2012 at 3:55 PM

@MarkBaker

any news on this issue yet? Although v1.7.6 is working fine, I would like to be able to use the latest version.

Coordinator
Aug 12, 2012 at 9:32 PM

I haven't been able to identify any circumstance that can cause the autoloader to fail other than conflicts with other libraries using autoloaders that don't conforml to the SPL autoloader registration standards

Feb 13, 2013 at 11:34 AM
Edited Feb 13, 2013 at 11:35 AM
For anyone wondering, I solved this in my autoloader. Separating durectories in classnames with an underscore is something PHP should handle, but doesn't always do. Alter this autoloader to your taste and things will work as far as autoloading goes:

<?php


function my_autoloader($_class)
{


    //for classes where dir separator was replaced by an underscore
    if (strpos($_class, '_') !== False)
    {
        $_class = str_replace('_', DIRECTORY_SEPARATOR ,$_class);
        require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $_class . '.php';

    }

    else
    {
        $possible_class_locations = array();

        $possible_class_locations[] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $_class . '.class.php';
        $possible_class_locations[] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $_class . '.php';
        $possible_class_locations[] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'phpexcel' . DIRECTORY_SEPARATOR . $_class . '.php';
        foreach($possible_class_locations as $cls)
        {
            if(file_exists($cls))
            {
                require_once($cls);
                break;
            }
            else
            {
                //echo $cls . ' doesnt exist!' . "<br />";
                continue;
            }
        }
        //require_once WEBROOT . '/classes/' . $className . '.class.php';
    }

}
spl_autoload_register('my_autoloader');

?>
Best regards,
Marv