Fatal error: Class 'PHPExcel_Shared_String' not found

12,978

Solution 1

There was a change introduced to the autoloader in the latest version of PHPExcel that appears to have broken backward compatibility with versions of PHP < 5.3.0

If you edit the Classes/PHPExcel/Autoloader.php file and change line 58, which should read

return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'), true, true);

to

return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));

I've already made a change to the develop branch on github to test for the PHP version and execute the appropriate line

While this was not deliberate, please note that we really are trying to get users to upgrade to at least version 5.3.0 of PHP, because we can't address any of the memory/performance issues that users working with large spreadsheets complain about until we can use some of the new features available in more recent versions of PHP. Version 5.2 of PHP is no longer supported, and even version 5.3 is end-of-life and will be unsupported before the end of this year

Solution 2

struggled with this issue for a long time under Linux and PHP 5.4x. In the end, in addition to the fix above, I resorted to changing the code on line 73 of the Autoloader file which sets the $pClassFilePath variable from relative (using PHPEXCEL_ROOT) to absolute following the machines file tree. This might only be a hack, but it saved my sanity after several days of trying. Hope this helps someone. Cheers

Share:
12,978
muhsin_ap
Author by

muhsin_ap

Updated on June 04, 2022

Comments

  • muhsin_ap
    muhsin_ap over 1 year

    I have used PHPExcel for my codeigniter app and it is working perfectly in localhost, but when I host this to server, I am getting following error :

    Fatal error: Class 'PHPExcel_Shared_String' not found in \xx\xx\xx third_party\PHPExcel\Autoloader.php on line 36

  • Mark Baker
    Mark Baker almost 7 years
    We're obsessed with it because it's so useful, when integrating with other libraries, when eliminating the need to include every single thing even when it isn't needed (to keep memory usage low)... and it doesn't mean adding new problems, unless people don't know what they're doing... and the autoloader means that you only need to include one php file
  • Mark Baker
    Mark Baker almost 7 years
    And this issues isn't an autoloader issue specificlly, it's a backward compatibility issue
  • Gianluca Ghettini
    Gianluca Ghettini almost 7 years
    autoloader solves a non-problem: a library may ships with tons of php files, it should have one file called include.php which includes its own files. In order to use such library just include that single file. Is that simple
  • Mark Baker
    Mark Baker almost 7 years
    Why do you then load every single individual file from that single included file, whether you need it or not? That's incredibly wasteful of memory, and highly inefficient.... an autoloader eliminates all that, only loading those files that are needed at the point when they are needed, so that "non-problem" of potentially excessive memory usage is significantly reduced
  • Mark Baker
    Mark Baker almost 7 years
    And as it stands, the PHPExcel library provides a single file to include that works with the autoloader.... so isn't that simple?
  • Mark Baker
    Mark Baker almost 7 years
    And the examples obviously aren't clear enugh in telling you that it's Classes/PHPExcel.php?
  • Gianluca Ghettini
    Gianluca Ghettini almost 7 years
    In C you can include the entire world but only the functions actually called by the program make their way to the linker and the final executable
  • Mark Baker
    Mark Baker almost 7 years
    C is a compiled language; PHP is a scripting language; you're comparing totally different fish... but perhaps if you think so little of PHP and so highly of C, you should just be coding in C and leave PHP alone
  • Gianluca Ghettini
    Gianluca Ghettini almost 7 years
    BTW, I had a non printable character in my php script file, I removed it and now the include works. I think PHPExcel is a great library but the documentation is really poor: the names of the example files are different, getActiveSheet() doesn't work anymore. I can't find the very basic and simple example of iterating the rows and the columns of a spreadsheet. I feel I'm learning the library by trial and error on StackOverflow. It happens the same for AngularJS
  • Mark Baker
    Mark Baker almost 7 years
    What do you expect the Documentation or API Documentation to have that it doesn't have? Or the examples to demonstrate different features? Thenames of the example files are different are different to what? getActiveSheet() works otherwise almost the entire library wouldn't work at all; iterating the rows/cells example is 28iterator.php
  • Mark Baker
    Mark Baker almost 7 years
    And why does somebody with over 3k rep on SO hijack the comments of an answer to raise these issues?
  • Gianluca Ghettini
    Gianluca Ghettini almost 7 years
    because according to the SO rules there's no need to duplicate questions over and over, better attach to the comment thread
  • Mark Baker
    Mark Baker almost 7 years
    Well a rant against autoloaders wasn't really asking any question! It didn't tell me you were having problems with PHPExcel at all