From cb7162a995810fe14203660e160edb9b523f7d5a Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 2 May 2012 11:07:24 -0400 Subject: [PATCH] Use prepend for autoloading on PHP 5.3+ Signed-off-by: Edward Z. Yang --- NEWS | 1 + library/HTMLPurifier/Bootstrap.php | 51 +++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index 058c14d1..dcd196df 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier this also means it's no longer possible to override attribute transforms in later modules. No internal code was using this but this may break some clients. +- Use prepend for SPL autoloading on PHP 5.3 and later. 4.4.0, released 2012-01-18 # Removed PEARSax3 handler. diff --git a/library/HTMLPurifier/Bootstrap.php b/library/HTMLPurifier/Bootstrap.php index 607c5b18..ae503320 100644 --- a/library/HTMLPurifier/Bootstrap.php +++ b/library/HTMLPurifier/Bootstrap.php @@ -70,32 +70,37 @@ class HTMLPurifier_Bootstrap if ( ($funcs = spl_autoload_functions()) === false ) { spl_autoload_register($autoload); } elseif (function_exists('spl_autoload_unregister')) { - $buggy = version_compare(PHP_VERSION, '5.2.11', '<'); - $compat = version_compare(PHP_VERSION, '5.1.2', '<=') && - version_compare(PHP_VERSION, '5.1.0', '>='); - foreach ($funcs as $func) { - if ($buggy && is_array($func)) { - // :TRICKY: There are some compatibility issues and some - // places where we need to error out - $reflector = new ReflectionMethod($func[0], $func[1]); - if (!$reflector->isStatic()) { - throw new Exception(' - HTML Purifier autoloader registrar is not compatible - with non-static object methods due to PHP Bug #44144; - Please do not use HTMLPurifier.autoload.php (or any - file that includes this file); instead, place the code: - spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\')) - after your own autoloaders. - '); + if (version_compare(PHP_VERSION, '5.3.0', '>=')) { + // prepend flag exists, no need for shenanigans + spl_autoload_register($autoload, true, true); + } else { + $buggy = version_compare(PHP_VERSION, '5.2.11', '<'); + $compat = version_compare(PHP_VERSION, '5.1.2', '<=') && + version_compare(PHP_VERSION, '5.1.0', '>='); + foreach ($funcs as $func) { + if ($buggy && is_array($func)) { + // :TRICKY: There are some compatibility issues and some + // places where we need to error out + $reflector = new ReflectionMethod($func[0], $func[1]); + if (!$reflector->isStatic()) { + throw new Exception(' + HTML Purifier autoloader registrar is not compatible + with non-static object methods due to PHP Bug #44144; + Please do not use HTMLPurifier.autoload.php (or any + file that includes this file); instead, place the code: + spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\')) + after your own autoloaders. + '); + } + // Suprisingly, spl_autoload_register supports the + // Class::staticMethod callback format, although call_user_func doesn't + if ($compat) $func = implode('::', $func); } - // Suprisingly, spl_autoload_register supports the - // Class::staticMethod callback format, although call_user_func doesn't - if ($compat) $func = implode('::', $func); + spl_autoload_unregister($func); } - spl_autoload_unregister($func); + spl_autoload_register($autoload); + foreach ($funcs as $func) spl_autoload_register($func); } - spl_autoload_register($autoload); - foreach ($funcs as $func) spl_autoload_register($func); } } -- 2.11.4.GIT