Php 类中的访问常量
我尝试访问类中的常量: file1.php file2.php 我使用了一些变体,如:Php 类中的访问常量,php,class,Php,Class,我尝试访问类中的常量: file1.php file2.php 我使用了一些变体,如: public function __construct() { self::$table = SUBDOMAIN.'zi_utp'; } 但总有这样的错误: PHP Parse error: syntax error, unexpected '.', expecting ',' or ';' 或 非常感谢您的任何提示!我还阅读了有关stackoverflow的其他类似问题,但没有人正确回答此问题:/ 更
public function __construct()
{
self::$table = SUBDOMAIN.'zi_utp';
}
但总有这样的错误:
PHP Parse error: syntax error, unexpected '.', expecting ',' or ';'
或
非常感谢您的任何提示!我还阅读了有关stackoverflow的其他类似问题,但没有人正确回答此问题:/
更新
现在,我测试了以下解决方案:
file2.php
或
file1.php
结果
Access to undeclared static property OR
syntax error, unexpected T_VARIABLE
使用
const
定义常数。看看您只能将变量初始化为标量值(或数组)。如果您只是声明public$table
,那么在构造函数中初始化它应该可以工作。
PHP Parse error: syntax error, unexpected '.', expecting ',' or ';'
syntax error, unexpected T_VARIABLE
public $table;
public function __construct()
{
self::$table = SUBDOMAIN.'zi_utp';
}
define('SUBDOMAIN',$subdomain);
const SUBDOMAIN = $subdomain;
Access to undeclared static property OR
syntax error, unexpected T_VARIABLE