php类名和方法名重复的冲突

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级别的错误,提示在未来版本中会彻底抛弃类同名方法作为构造函数。但程序仍然会正常执行。

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP的解决方法是使用__construct作为构造方法的方法名。即:

<?php
    class a {
        //function a(){
        //    
         //}         
        function __construct() { 
        }
    }
?>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容