我尝试在类中访问常量:
file1.php
[...]
define('SUBDOMAIN','name');
require_once 'file2.php';
[...]
file2.php
[...]
class Gdl_Ute extends Response_Model {
public $table = SUBDOMAIN.'zi_utp';
public function statuses()
{
[...]
我使用了一些变体:
public function __construct()
{
self::$table = SUBDOMAIN.'zi_utp';
}
但总有一个错误:
PHP Parse error: syntax error, unexpected '.', expecting ',' or ';'
或
syntax error, unexpected T_VARIABLE
非常感谢任何提示!我还在stackoverflow上阅读了其他类似的问题,但没有人正确回答这个问题:/
更新 现在我测试以下解决方案:
file2.php
public $table;
public function __construct()
{
self::$table = SUBDOMAIN.'zi_utp';
}
OR
file1.php
define('SUBDOMAIN',$subdomain);
const SUBDOMAIN = $subdomain;
RESULT
Access to undeclared static property OR
syntax error, unexpected T_VARIABLE