-->

PHP资讯

您的当前位置:首页 > 资讯 > PHP基础

php7整理-废弃功能

2020-03-23 13:17:33  来源:admin 点击:556

废弃功能

·         PHP4风格的构造函数将被弃用。(和类名同名的方法视为构造方法,这是PHP4的语法。)

·         静态调用非静态方法将被弃用。

PHP4风格的构造函数

PHP4式构造函数,它与类的名称相同,因为它们是在所定义类的方法,现在已过时,并且将在未来被移除。如果PHP4的构造仅仅是一个类中定义构造函数,PHP7将发出E_DEPRECATED。类实现构造函数 __construct()方法不受影响。

示例

<?php
class A {
   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();
?>

这将在浏览器产生以下输出 -

Deprecated: Non-static method A::b() should not be called statically in...
Non-static call


相关文章更多 >

© 2024版权所有 水水网

电话:171780793