首页 > 解决方案 > 我在代码 {Login-Signup form} 中收到 PHP 已弃用错误

问题描述

我收到以下错误:

代码中有什么错误?

[27-May-2018 20:37:37 UTC] PHP Deprecated:  Methods with the same name as their class will not be constructors in a future version of PHP; FGMembersite has a deprecated constructor in /home/gurudev/public_html/user/include/fg_membersite.php on line 24
[27-May-2018 20:37:37 UTC] PHP Deprecated:  Methods with the same name as their class will not be constructors in a future version of PHP; FormValidator has a deprecated constructor in /home/gurudev/public_html/user/include/formvalidator.php on line 66
[27-May-2018 20:37:58 UTC] PHP Deprecated:  Methods with the same name as their class will not be constructors in a future version of PHP; FGMembersite has a deprecated constructor in /home/gurudev/public_html/user/include/fg_membersite.php on line 24
[27-May-2018 20:37:58 UTC] PHP Deprecated:  Methods with the same name as their class will not be constructors in a future version of PHP; FormValidator has a deprecated constructor in /home/gurudev/public_html/user/include/formvalidator.php on line 66
[27-May-2018 20:37:58 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function mysql_connect() in /home/gurudev/public_html/user/include/fg_membersite.php:773
Stack trace:
#0 /home/gurudev/public_html/user/include/fg_membersite.php(729): FGMembersite->DBLogin()
#1 /home/gurudev/public_html/user/include/fg_membersite.php(86): FGMembersite->SaveToDatabase(Array)
#2 /home/gurudev/public_html/user/register.php(6): FGMembersite->RegisterUser()
#3 {main}
  thrown in /home/gurudev/public_html/user/include/fg_membersite.php on line 773

源文件给出: http ://cache.youthhustle.com/files/source.txt

标签: phpfatal-error

解决方案


[27-May-2018 20:37:37 UTC] PHP 已弃用:与其类同名的方法在 PHP 的未来版本中将不再是构造函数;FGMembersite 在第 24 行的 /home/gurudev/public_html/user/include/fg_membersite.php 中有一个已弃用的构造函数

这意味着该类的构造函数以 php 在未来版本中不再支持的方式命名。

class FGMembersite{

    public function FGMemmbersite() : void{
        echo "something";
    }
}

class FGMembersite{

    public function __construct() : void{
        echo "something";
    }
}

new FGMembersite();

这两个类都会回显“某事”,不同之处在于第一个构造函数方法在未来的 php 版本中将不再工作,因为它与类本身同名;它必须是 __construct()

它警告你,你的代码可能会破坏这条线。


推荐阅读