读取 INI 到 class const PHP

Read INI to class const PHP

我在尝试 运行 以下代码时在 TEXT 行收到错误 Parse error: syntax error, unexpected '(', expecting ',' or ';'。我真的需要能够将内容写入 Config::TEXT。知道我哪里出错了吗?

class Config {
    const DB_HOST     = 'localhost:3388',
          DB_NAME     = 'otplatform',
          DB_USER     = 'root',
          DB_PASS     = '',
          DEBUG       = true,
          LANGUAGE    = "en",
          TEXT        = parse_ini_file('translate/' . LANGUAGE . '.ini',1);
}

你不能这样声明多个常量。使用它来定义倍数:

$constants = array(
    'ONE'   => 1,
    'TWO'   => 2,
    'THREE' => 3,
);

apc_define_constants('numbers', $constants);

http://php.net/manual/en/function.apc-define-constants.php

使用以下任一约定:

define("CONSTANT", "Hello world.");

在class范围内:

const test = 'foobar!';

http://php.net/manual/en/function.constant.php

另外回答你的问题,你不能在定义过程中解析文件。