Fatal error: Class 'PHPExcel_Shared_String' not found
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
muhsin_ap
Updated on June 04, 2022Comments
-
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 almost 7 yearsWe'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 almost 7 yearsAnd this issues isn't an autoloader issue specificlly, it's a backward compatibility issue
-
Gianluca Ghettini almost 7 yearsautoloader 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 almost 7 yearsWhy 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 almost 7 yearsAnd as it stands, the PHPExcel library provides a single file to include that works with the autoloader.... so isn't that simple?
-
Mark Baker almost 7 yearsAnd the examples obviously aren't clear enugh in telling you that it's
Classes/PHPExcel.php
? -
Gianluca Ghettini almost 7 yearsIn 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 almost 7 yearsC 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 almost 7 yearsBTW, 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 almost 7 yearsWhat do you expect the Documentation or API Documentation to have that it doesn't have? Or the examples to demonstrate different features? The
names 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 is28iterator.php
-
Mark Baker almost 7 yearsAnd why does somebody with over 3k rep on SO hijack the comments of an answer to raise these issues?
-
Gianluca Ghettini almost 7 yearsbecause according to the SO rules there's no need to duplicate questions over and over, better attach to the comment thread
-
Mark Baker almost 7 yearsWell a rant against autoloaders wasn't really asking any question! It didn't tell me you were having problems with PHPExcel at all