【发布时间】:2014-06-06 14:53:42
【问题描述】:
我正在使用 PHPMailer,并希望扩展该类,以便我可以预先设置一些值。我已经设置了自动加载,所以在调用它之前我不需要该文件。我不希望实际设置位于 /var/www/classes/myPHPMailer.php 中,因为我有两台配置不同的服务器,因此请在 Git 忽略的另一个文件中找到设置。所以,它看起来像下面这样。
主文件
<?php
function __autoload($class)
{
if(file_exists('/var/www/classes/'.strtolower($class).'.php'))
{require_once '/var/www/classes/'.strtolower($class).'.php';}
}
$mailer=new myPHPMailer(true);
//...
$mailer->send();
?>
文件名:/var/www/classes/myPHPMailer.php
<?php
require_once ('/var/www/private/email.php');
class myPHPMailer extends myPHPMailer_temp {}
?>
文件名:/var/www/private/email.php
<?php
require_once ('/var/www/other_classes/PHPMailer/PHPMailerAutoload.php');
class myPHPMailer_temp extends PHPMailer {
public function __construct($allow_exceptions=false){
$this->isSMTP();
$this->SMTPDebug = 0;
$this->Host = "smtp.gmail.com";
$this->Port = 587;
$this->SMTPSecure = "tls";
$this->SMTPAuth = true;
$this->Username = "Username@gmail.com";
$this->Password = "Password";
}
}
?>
我收到了Fatal error: Class 'SMTP' not found in /var/www/other_classes/PHPMailer/PHPMailer/class.phpmailer.php on line 1173
如果我require_once /var/www/private/email.php; 并直接唤起myPHPMailer_temp,我不会得到错误。
使用自动加载器时如何扩展此类?另外,我如何查看 PHP 将在哪些目录中搜索?在第 1173 行 ($this->smtp = new SMTP;) 之前,我希望查看它正在查找的目录,以便进行故障排除。
谢谢
【问题讨论】:
-
您或许应该考虑使用一致的类命名约定。这是我见过的最奇怪的组合!
-
@Seer。请解释为什么它是悲剧。
-
它看起来像是混合了各种样式、驼峰式大小写、下划线和一些大写字母。我知道这部分是 PHPMailers 的错误,但我会称它为
TempPhpMailer之类的东西。只是为了保持一致。 :)
标签: php oop phpmailer autoloader