PHP7 废弃特性
PHP4 风格的构造函数
在 PHP4 中类中的函数可以与类名同名,这一特性在 PHP7 中被废弃,同时会发出一个 E_DEPRECATED 错误。当方法名与类名相同,且类不在命名空间中,同时PHP5的构造函数(__construct)不存在时,会产生一个 E_DEPRECATED 错误。
例如:
<?php
class A {
function A() {
print('Style Constructor');
}
}
?>
function A() {
print('Style Constructor');
}
}
?>
以上程序执行输出结果为:
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...
以静态的方式调用非静态方法
以静态的方式调用非静态方法,不再支持:
例如:
<?php
class A {
function b() {
print('Non-static call');
}
}
A::b();
?>
class A {
function b() {
print('Non-static call');
}
}
A::b();
?>
以上程序执行输出结果为:
Deprecated: Non-static method A::b() should not be called statically in...
Non-static call