ECSHOP中出现Redefining already defined constructor for class的解决方法

刘连康 网站建设评论8,0172字数 1259阅读4分11秒阅读模式

在安装完ecshop2.7.3后,由于ECSHOP模板架设的服务器php版本过高,很多地方就会出现如下报错:

Redefining already defined constructor for class XXX

检查代码可以发现,原来是对应位置的某个类的构造函数有问题,具体写法如下:

/**
     * 构造函数
     *
     * @access  public
     * @param
     *
     * @return void
     */
    function alipay()
    {
    }

    function __construct()
    {
        $this->alipay();
    }

其中使用和类名相同点函数名作为构造函数是php4时代的写法,而现在就不同了,现在php5时代的构造函数是 __construct(),ECSHOP为了兼容老版本的php,所以采用了上面的写法。

 

可是你们知道吗?从php5.4开始,对于这样的两种写法同时出现的情况,要求必须__construct()在前,同名函数在后,所以我们只需要对调两个函数的位置就可以搞定了。

 

下面是详细的解决方案:

 

登陆FTP,使用代码编辑器notepad++,打开ECSHOP目录下的includes/cls_captcha.php文件,然后把代码1放到代码2的后面,文件保存好之后就传回去覆盖,这个错误问题也就解决掉了。

 

代码2:

  /**
   * 构造函数
   *
   * @access  public
   * @param
   *
   * @return void
   */
  function __construct($folder = '', $width = 145, $height = 20)
 {
     $this->captcha($folder, $width, $height);
 }

 

代码1:

  /**
      * 构造函数
      *
      * @access  public
      * @param   string  $folder     背景图片所在目录
      * @param   integer $width      图片宽度
      * @param   integer $height     图片高度
      * @return  bool
      */
    function captcha($folder = '', $width = 145, $height = 20)
    {
        if (!empty($folder))
        {
            $this->folder = $folder;
        }
  
        $this->width    = $width;
        $this->height   = $height;
  
        /* 检查是否支持 GD */
        if (PHP_VERSION >= '4.3')
        {
  
            return (function_exists('imagecreatetruecolor') || function_exists('imagecreate'));
        }
        else
        {
  
            return (((imagetypes() & IMG_GIF) > 0) || ((imagetypes() & IMG_JPG)) > 0 );
        }
    }

 

 

本文为原创文章,版权归作者所有,未经授权,禁止抄袭,否则将追究法律责任!

欢迎转载,转载请注明作者和出处,谢谢!

作者:刘连康

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
刘连康
  • 本文由 发表于 2017年12月24日 06:32:19
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定