PHPExcel not loading .xlsx in PHP earlier than 5.2.11

I worked on an legacy system running PHP 5.2.6 on Windows and I can’t update it.

With php_zip enabled, PHPExcel loads .xls but still not .xlsx.
When loading a .xlsx, it’s simply die without any error message.

I have enabled all error report, but still no any clue.

ini_set('display_errors', 1);

After some brute-force debugging, I found the root cause:

The two lines of


in Settings.php caused PHP fatal error and halted the output.
Worse still, those statements are suppressed by @ operator

     * Set default options for libxml loader
     * @param int $options Default options for libxml loader
    public static function setLibXmlLoaderOptions($options = null)
        if (is_null($options)) {
            $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
        @libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR)); 
        self::$_libXmlLoaderOptions = $options;
    } // function setLibXmlLoaderOptions

     * Get default options for libxml loader.
     * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
     * @return int Default options for libxml loader
    public static function getLibXmlLoaderOptions()
        if (is_null(self::$_libXmlLoaderOptions)) {
            self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
        @libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
        return self::$_libXmlLoaderOptions;
    } // function getLibXmlLoaderOptions

libxml_disable_entity_loader is only available >= PHP 5.2.11

Comment it seems didn’t hurt anything. Problem solved!

Well, perfect example of why @ operator evil.

I have filed an issue to developers on GitHub, because PHPExcel claim to support down to 5.2.0.

3 Replies to “PHPExcel not loading .xlsx in PHP earlier than 5.2.11”

Leave a Reply to Oleg Nerus Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.