PHP报错Methods with the same name as their class will not be constructors in a future version of PHP

PHP与SEO 思享 658浏览
摘要:
当PHP的版本升级到更高的版本时,经常会拒绝一些函数或语法。当笔者从PHP 5.5升级到PHP 7.0,访问原站点时出现以下错误:。上面的英文错误字面意思是定义类时使用了与类名相同的函数名。在PHP5中运行没有错误,但是在PHP 7中不允许这样写。解决办法很简单。只要把类名相同的函数名改成“__construct”,就是大家熟知的构造函数。

PHP版本在升级到高版本的时候往往会出现某些函数或语法被屏弃的现象,笔者环境从PHP 5.5 升级到PHP 7.0的时候原来的站点访问的时候就出现了如下错误:

PHP Deprecated:  Methods with the same name as their class will not be constructors in a future version of PHP; AES has a deprecated constructor in

从上面英文错误的字面上理解是在定义类的时候使用了与类名相同的函数名称,在PHP5里运行实际是没有报错的,但在PHP 7里就不允许这样写,解决办法很简单,只要把与类名相同的函数名改为“__construct”,也就是我们熟知的构造函数咯。

推荐阅读

Function get_magic_quotes_gpc() is deprecated报错解决办法

在 PHP 7.4 及更高版本中, get_magic_quotes_gpc() 函数已被弃用。 This means that code using this function will raise a warning or error.以下是解决......

PHP提示:Warning: count():Parameter must be an array or an object that implements Countable

错误原因:PHP7.2以后,count()函数的参数无效时会抛出warning警告。...

PHP7.4 报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated.

PHP7.4运行项目报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated。只需交换 implode() 函数的两个参数!...