douyan8413 2014-02-26 18:46
浏览 95
已采纳

如何在php中静态调用函数?

I am using pear to send mail in PHP. I've followed the example that is on here (http://pear.php.net/manual/en/package.mail.mail.send.php). However, I am getting this error message.

Strict Standards: Non-static method Mail::factory() should not be called statically in C:\xampp\htdocs\functions.php on line 43

So I've been trying to get this Strict Standards message to not show up.

This is my code:

$smtpinfo["host"] = "********";
$smtpinfo["port"] = "587"; 
$smtpinfo["auth"] = true; 
$smtpinfo["username"] = $mail_username; 
$smtpinfo["password"] = $mail_password; 

## This line below is causing the problem ## 
$mail =& Mail::factory("smtp", $smtpinfo);  // <-- Line 43

I've read many Stack Overflow Q&A that say just add a @ to the beginning of $mail. And it is true, it makes the error disappear, but I feel like that just hides the error, and doesn't actually solve the problem.

@$mail =& Mail::factory("smtp", $smtpinfo); 

How do I not call the method above as statically?

Even the documentation on this page (http://pear.php.net/manual/en/package.mail.mail.send.php), says This function cannot be called statically.... but the example they gave is the same way I am calling the method?!

Please don't answer just add @ in front to remove the strict standard or E_ALL & ~E_STRICT ... that is not a solution!

  • 写回答

3条回答 默认 最新

  • dongxiongshi9952 2014-02-26 18:53
    关注

    If you take a look at the PEAR Mail class, you can see that there are a few instances of it calling methods statically when the methods are not declared as static.

    Change line 74 of Mail.php from:

    function &factory($driver, $params = array())
    

    to:

    static function &factory($driver, $params = array())
    

    The other less desirable alternative would be to modify your php.ini configuration to disregard the E_STRICT warnings, but I believe fixing the cause of the error message is better than hiding it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题