Skip to content

Commit

Permalink
Provide fallback autoloading for old PHP versions, see PHPMailer#113
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Oct 29, 2013
1 parent 41415a8 commit e26e978
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion PHPMailerAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public function __construct($exceptions = false)
{
$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';
}
}
Expand Down

0 comments on commit e26e978

Please sign in to comment.