如何在PHP中静态调用函数? [英] How to not call a function statically in php?

查看:229
本文介绍了如何在PHP中静态调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用梨来发送邮件。我按照这里的例子( http:/ /pear.php.net/manual/en/package.mail.mail.send.php )。但是,我收到此错误消息。


严格标准:非静态方法Mail :: factory()不应该静态调用C: \xampp\htdocs\functions.php在第43行


所以我一直在试图得到这个严格的标准信息不显示



这是我的代码:

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

##以下这一行导致问题##
$ mail =& Mail :: factory(smtp,$ smtpinfo); //< - Line 43

我读了很多堆叠溢出问题与答案,只要添加一个 @ $ mail 的开头。这是真的,它使错误消失,但我觉得这只是隐藏错误,并没有真正解决问题。

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

如何不静态调用上述方法?



甚至这个页面上的文档( http://pear.php.net/manual/en/package.mail.mail.send.php ),说这个函数不能静态调用。 code> ...但是他们给出的例子与我打电话的方式一样?



请不要回答只需添加 @ 在前面删除严格的标准或 E_ALL& 〜E_STRICT ...这不是一个解决方案!

解决方案

如果你看看PEAR邮件类,您可以看到,当方法未声明为静态时,可以静态调用方法的一些实例。



更改第74行 Mail.php from:

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

to:

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



另一个不太可取的替代方法是修改您的 php.ini 配置,以忽略 E_STRICT 警告,但是我相信修复错误信息的原因比隐藏它更好。


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!

解决方案

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.

这篇关于如何在PHP中静态调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆