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

PHP与SEO 思享 193浏览
摘要:
当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”,也就是我们熟知的构造函数咯。

推荐阅读

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() 函数的两个参数!...

百度自动推送php实现代码

我们知道主动推送有助于搜索引擎抓取和收录网站内容,wordpress或者主流CMS其实已经集成了推送功能。但是如果我们要定期归还,而不是只在发布的时候推一次。这个功能可以通过结合PHP和Pagoda Panel的预定任务来实现。$api = '百度站......