PHP7警告信息

                   作者:老葛, 亚艾元软件


我们做好的一个网站,Drupal7的,迁移到了PHP7环境上面,报了一大堆的错误消息:

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context_required has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context_optional has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; panels_cache_object has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context_required has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context_optional has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; panels_cache_object has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

 

这些都是和Ctools模块相关的,升级ctools模块到最新的dev版本,我们最初用的ctools 7.x-1.9,2015年的一个稳定版本,那个时候PHP7的正式版还没有出来。

 

升级过后,警告信息基本没有了,但是还有1-2条:

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; panels_cache_object has a deprecated constructor require_once() ( 127 /var/www/html/zhaopin/sites/all/modules/standard/ctools/ctools.module).

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; panels_allowed_layouts has a deprecated constructor include_once() ( 565 /var/www/html/zhaopin/includes/theme.inc).

 

原先以为是ctools的问题,仔细一看,panels_cache_objectpanels_allowed_layouts 应该是Panels模块的东西。将Panels模块,从稳定版本,升级到Dev版。这个问题就解决了。

 

相信,在今年,CtoolsPanels应该有支持PHP7的稳定版本发布。

 

这个问题的根源:

@@ -42,7 +42,7 @@ class ctools_context {

   var $restrictions = array();

   var $empty = FALSE;

 

-  function ctools_context($type = 'none', $data = NULL) {

+  function __construct($type = 'none', $data = NULL) {

     $this->type  = $type;

     $this->data  = $data;

     $this->title = t('Unknown context');

 

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

 

将与类同名的构造函数,改为__construct即可。

论坛: 
Drupal版本: 

关注我们的微信

关注我们,体验一下Drupal微信(Wechat)模块的最新进展

Think in Drupal 官方微信 亚艾元官方微信