Skip to content

Commit f77d3d1

Browse files
author
MarkBaker
committed
Bugfix: Work Item PHPOfficeGH-384 - DOM loadHTMLFile() failing with options flags when using PHP < 5.4.0
Additional check that libxml is running at an appropriate version by testing if libxml flag value constants are defined
1 parent 57ce19d commit f77d3d1

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Classes/PHPExcel/Reader/HTML.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
424424
// Create a new DOM object
425425
$dom = new DOMDocument;
426426
// Reload the HTML file into the DOM object
427-
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
427+
if ((version_compare(PHP_VERSION, '5.4.0') >= 0) && defined(LIBXML_DTDLOAD)) {
428428
$loaded = $dom->loadHTMLFile($pFilename, PHPExcel_Settings::getLibXmlLoaderOptions());
429429
} else {
430430
$loaded = $dom->loadHTMLFile($pFilename);

Classes/PHPExcel/Settings.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,12 @@ public static function getPdfRendererPath()
363363
*/
364364
public static function setLibXmlLoaderOptions($options = null)
365365
{
366-
if (is_null($options)) {
366+
if (is_null($options) && defined(LIBXML_DTDLOAD)) {
367367
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
368368
}
369-
@libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
369+
if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
370+
@libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
371+
}
370372
self::$_libXmlLoaderOptions = $options;
371373
} // function setLibXmlLoaderOptions
372374

@@ -378,10 +380,12 @@ public static function setLibXmlLoaderOptions($options = null)
378380
*/
379381
public static function getLibXmlLoaderOptions()
380382
{
381-
if (is_null(self::$_libXmlLoaderOptions)) {
383+
if (is_null(self::$_libXmlLoaderOptions) && defined(LIBXML_DTDLOAD)) {
382384
self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
383385
}
384-
@libxml_disable_entity_loader(self::$_libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
386+
if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
387+
@libxml_disable_entity_loader(self::$_libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
388+
}
385389
return self::$_libXmlLoaderOptions;
386390
} // function getLibXmlLoaderOptions
387391
}

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Planned for v1.8.1
2929
- Bugfix: (MBaker) - Fix to ensure that current cell is maintained when executing formula calculations
3030
- Bugfix: (MBaker) Work Item GH-350 - Keep/set the value on Reader _loadSheetsOnly as NULL, courtesy of Restless-ET
3131
- Bugfix: (MBaker) Work Item CP18105 - Loading an Excel 2007 spreadsheet throws an "Autofilter must be set on a range of cells" exception
32-
- Bugfix: (MBaker) - Fix to autoloader registration for backward compatibility with PHP 5.2.0 not accepting the prepend flag
32+
- Bugfix: (MBaker) Work Item GH-388 - Fix to autoloader registration for backward compatibility with PHP 5.2.0 not accepting the prepend flag
3333
- Bugfix: (MBaker) Work Item GH-384 - DOM loadHTMLFile() failing with options flags when using PHP < 5.4.0
3434
- Bugfix: (MBaker) - Fix for percentage operator in formulae for BIFF Writer
3535
- General: (MBaker) - Small performance improvement for autosize columns

0 commit comments

Comments
 (0)