【问题标题】:PHP Registry has a deprecated constructor Error [duplicate]PHP Registry 有一个已弃用的构造函数错误 [重复]
【发布时间】:2018-08-16 11:14:04
【问题描述】:

我在运行 php 脚本时遇到Registry has a deprecated constructorError。它在第 261 行显示错误。转到该行我有以下代码。如何避免此错误。

class Registry {

function Registry() {

    define("CWD", ($getcwd = getcwd() ? $getcwd : "."));
    $config = array();
    include INCLUDES . "config.php";

    if (sizeof($config) == 0) {
        if (file_exists(INCLUDES . "config.php")) {
            exit( "<div style=\"border: 1px dashed #cc0000;font-family:Tahoma;background-color:#FBEEEB;width:100%;padding:10px;color:#cc0000;\"><strong>Welcome to EvolutionScript 5.1 FULL</strong><a></a><br>Before you can begin using EvolutionScript you need to perform the installation procedure. <a href=\"" . (file_exists( "install/install.php" ) ? "" : "../") . "install/install.php\" style=\"color:#000;\">Click here to begin ...</a><br></div>" );
        }
        else {
            exit("<br /><br /><strong>Configuration</strong>: includes/config.php does not exist. Please fill out the data in config.php.new and rename it to config.php");
        }
    }

    $this->config = $config;

    define("TABLE_PREFIX", trim($this->config['Database']['tableprefix']));
    define("COOKIE_PREFIX", (empty($this->config['Misc']['cookieprefix']) ? "ptc" : $this->config['Misc']['cookieprefix']) . "_");
  }
}

【问题讨论】:

  • 使用__construct() 而不是Registry()
  • 我认为你应该使用function __construct() {} 而不是function Registry() {}
  • 类注册表{
  • 使用函数 __construct() 页面不工作

标签: php class constructor


【解决方案1】:

与类名命名相同的构造函数被认为是 PHP4 样式,并且自 PHP 7 起已被弃用。我知道在其他 OOP 语言中使用这种约定很常见,但 PHP 提倡名为 __construct() 的魔术方法。更多信息在这里:http://php.net/manual/en/migration70.deprecated.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-17
    • 2018-10-24
    • 2020-04-20
    • 2017-08-31
    • 2014-08-19
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多