0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-03 05:11:52 +00:00

Use prepend for autoloading on PHP 5.3+

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
Edward Z. Yang 2012-05-02 11:07:24 -04:00
parent 2189a9430f
commit cb7162a995
2 changed files with 29 additions and 23 deletions

1
NEWS
View File

@ -14,6 +14,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
this also means it's no longer possible to override attribute this also means it's no longer possible to override attribute
transforms in later modules. No internal code was using this transforms in later modules. No internal code was using this
but this may break some clients. but this may break some clients.
- Use prepend for SPL autoloading on PHP 5.3 and later.
4.4.0, released 2012-01-18 4.4.0, released 2012-01-18
# Removed PEARSax3 handler. # Removed PEARSax3 handler.

View File

@ -70,32 +70,37 @@ class HTMLPurifier_Bootstrap
if ( ($funcs = spl_autoload_functions()) === false ) { if ( ($funcs = spl_autoload_functions()) === false ) {
spl_autoload_register($autoload); spl_autoload_register($autoload);
} elseif (function_exists('spl_autoload_unregister')) { } elseif (function_exists('spl_autoload_unregister')) {
$buggy = version_compare(PHP_VERSION, '5.2.11', '<'); if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
$compat = version_compare(PHP_VERSION, '5.1.2', '<=') && // prepend flag exists, no need for shenanigans
version_compare(PHP_VERSION, '5.1.0', '>='); spl_autoload_register($autoload, true, true);
foreach ($funcs as $func) { } else {
if ($buggy && is_array($func)) { $buggy = version_compare(PHP_VERSION, '5.2.11', '<');
// :TRICKY: There are some compatibility issues and some $compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
// places where we need to error out version_compare(PHP_VERSION, '5.1.0', '>=');
$reflector = new ReflectionMethod($func[0], $func[1]); foreach ($funcs as $func) {
if (!$reflector->isStatic()) { if ($buggy && is_array($func)) {
throw new Exception(' // :TRICKY: There are some compatibility issues and some
HTML Purifier autoloader registrar is not compatible // places where we need to error out
with non-static object methods due to PHP Bug #44144; $reflector = new ReflectionMethod($func[0], $func[1]);
Please do not use HTMLPurifier.autoload.php (or any if (!$reflector->isStatic()) {
file that includes this file); instead, place the code: throw new Exception('
spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\')) HTML Purifier autoloader registrar is not compatible
after your own autoloaders. 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 spl_autoload_unregister($func);
// Class::staticMethod callback format, although call_user_func doesn't
if ($compat) $func = implode('::', $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);
} }
} }