Nic*_*ick 2 php oop variables constants
我正在学习PHP中的OOP,我希望将值从变量赋值给类常量.我怎样才能做到这一点?
这是我的代码(不工作!):
class Dir {
const ROOT = $_SERVER['DOCUMENT_ROOT']."project/";
function __construct() {
}
}
Run Code Online (Sandbox Code Playgroud)
有没有解决方案,如何从变量中获取值,添加字符串并将其置于常量 - 在OOP中?
从手册页http://www.php.net/manual/en/language.oop5.constants.php可以找到:
The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.
Run Code Online (Sandbox Code Playgroud)