PHP 弃用:与类同名的方法在 PHP 的未来版本中将不再是构造函数 [英] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP

查看:61
本文介绍了PHP 弃用:与类同名的方法在 PHP 的未来版本中将不再是构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 CodeIgniter 中开发一个应用程序,我在注册时发送邮件时遇到错误.

I'm developing an application in CodeIgniter, and I'm getting an error in sending mail while registering.

PHP 已弃用:与它们的类同名的方法将不会被未来版本的 PHP 中的构造函数;emailcomm 已弃用构造函数/var/www/html/portal/application/libraries/emailcomm.php 第 3 行

PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; emailcomm has a deprecated constructor in /var/www/html/portal/application/libraries/emailcomm.php on line 3

我的图书馆文件在下面emailcomm.php

class emailcomm
{
     
    var $to;
    var $subject;
    var $message;
    var $from='From:';    
    
    function emailcomm()
    {
        $this->CI=&get_instance();   
        ini_set("SMTP","ssl://smtp.gmail.com");
            ini_set("smtp_port","465");

            $config['protocol'] = 'smtp';
            $config['smtp_host'] = 'smtp.gmail.com';
            $config['smtp_port'] = '465';
            $config['_smtp_auth']=TRUE;
            $config['smtp_user'] = 'contact-us@webtech.com';
            $config['smtp_pass'] = 'Web8*98*2015'; 
            $config['smtp_timeout'] = '60';
            $config['charset'] = 'utf-8';
            $config['wordwrap'] = TRUE;
            $config['mailtype'] = "html";
        
        $this->CI->load->library('email',$config); 
        
         $this->CI->email->initialize($config); 
    }
}

最近将服务器升级到php7,现在我的代码不能用了.我正在查看显示上述错误的错误日志.如何修复我的代码?

Recently upgraded the server to php7, and now my code doesn't work anymore. I'm going through the error logs showing the above error. How can I fix my code?

推荐答案

Solution : Rename your function name emailcomm() to __construct()

Solution : Rename your function name emailcomm() to __construct()

说明:在以前的 PHP 版本中,如果 PHP 找不到 __construct() 函数给定的类,它将通过类的名称搜索旧式构造函数,但现在旧式构造函数在 PHP 7.0已弃用,并将在未来版本中删除.你应该总是在新代码中使用 __construct() .阅读 php 手册

Explanation: In previous versions of PHP, if PHP cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class, but now old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code. Read php manual

   function __construct() {
      // copy your old constructor function code here
   }

这篇关于PHP 弃用:与类同名的方法在 PHP 的未来版本中将不再是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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