Provide fallback autoloading for old PHP versions, see #113

This commit is contained in:
Synchro 2013-10-29 11:58:40 +01:00
parent 41415a821f
commit e26e978d78
2 changed files with 11 additions and 2 deletions

View File

@ -30,4 +30,13 @@ function PHPMailerAutoload($classname)
}
}
spl_autoload_register('PHPMailerAutoload', true, true);
if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
//SPL autoloading was introduced in PHP 5.1.2
spl_autoload_register('PHPMailerAutoload', true, true);
} else {
//Fall back to traditional autoload for old PHP versions
function __autoload($classname)
{
PHPMailerAutoload($classname);
}
}

View File

@ -571,7 +571,7 @@ class PHPMailer
{
$this->exceptions = ($exceptions == true);
//Make sure our autoloader is loaded
if (!spl_autoload_functions() || !in_array('PHPMailerAutoload', spl_autoload_functions())) {
if (version_compare(PHP_VERSION, '5.1.2', '>=') and !spl_autoload_functions() || !in_array('PHPMailerAutoload', spl_autoload_functions())) {
require 'PHPMailerAutoload.php';
}
}