找回密码
 新建账号

[PHP] Deprecated: Methods with the same name as their class will not be constructor...

[复制链接]
php 发表于 2015/7/20 02:18 | 显示全部楼层 |阅读模式
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; a has a deprecated constructor in Path\xxx.php on line 9.

PHP OOP使用和类名相同的方法名作为构造方法,是 PHP4 的写法,PHP 5中同时支持__construct和类同名方法,但__construct方法具有优先性。

PHP 7开始使用和类名相同的方法名作为构造方法会报E_DEPRECATED级别的错误,提示在未来版本中会彻底抛弃类同名方法作为构造函数。
但程序仍然会正常执行。
  1. <?php
  2.         class a{
  3.                 function a(){
  4.                         
  5.                 }
  6.         }
  7. ?>
复制代码
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP 的解决方法是使用__construct作为构造方法的方法名。即:
  1. <?php
  2.         class a{
  3.                 function __construct(){
  4.                 }
  5.         }
  6. ?>
复制代码

手机版|轻松E站

GMT+8, 2024/4/20 04:41

快速回复 返回顶部 返回列表