PHP7 废弃特性

PHP4 风格的构造函数

在 PHP4 中类中的函数能够与类名同名,这一特性在 PHP7 中被废弃,同时会发出一个 E_DEPRECATED 错误。当方法名与类名相同,且类不在命名空间中,同时PHP5的构造函数(__construct)不存在时,会产生一个 E_DEPRECATED 错误。php

例如:函数

<?phpspa

class A {
   function A() {
      print('Style Constructor');
   }
}
?>

以上程序执行输出结果为:code

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...

以静态的方式调用非静态方法

以静态的方式调用非静态方法,再也不支持:it

例如:io

<?php
class A {
   function b() {
      print('Non-static call');
   }
}
A::b();
?>
 

以上程序执行输出结果为:function

Deprecated: Non-static method A::b() should not be called statically in... Non-static call
相关文章
相关标签/搜索