PHP-值从变量到常量 [英] PHP - value from variable to constant
本文介绍了PHP-值从变量到常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用PHP学习OOP,我想将值从变量转换为类常量.我该怎么办?
I'm learning OOP in PHP and I want to put value from variable to class constant. How can I do that?
这是我的代码(不起作用!):
This is my code (not working!):
class Dir {
const ROOT = $_SERVER['DOCUMENT_ROOT']."project/";
function __construct() {
}
}
有什么解决方法,如何从变量中获取值,添加字符串并将其置于常量中-在OOP中?
Is there any solution, how to take value from variable, add string and put it to constant - in 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.
这篇关于PHP-值从变量到常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文