我有以下测试代码:
namespace Test {
const ONE = 50;
class A {
const TWO = 5;
public function pA($string) {
return $string;
}
}
$a = new A();
print $a->pA($a::TWO);
print "This is a string: {$a->pA($a::TWO)}";
print "This is a namespace constant: " . ONE;
print "This is a namespace constant: " . \Test\ONE;
}
所有这些示例都可以工作,但不是我要找的。
我能否使用字符串组合来表示常量,就像前两个示例中那样?我尝试了许多组合,例如"${\Test\B}"
或"${B}"
或"${\B}"
,但到目前为止没有成功。
也许这是不可能的,我在过度思考,但无论如何...有没有一种方法可以做到这一点?
{\Test\ONE}
不能工作。也许应该考虑向PHP开发团队提交更改请求。 - hek2mgl