php const 字符串,我可以使用字符串连接在PHP中定义一个类CONST吗?
Imho,這個問題值得PHP 5.6的答案,感謝@jammin
comment
從PHP 5.6開始,你可以為一個常量定義一個靜態(tài)標(biāo)量表達式:
class Foo {
const BAR = "baz";
const HAZ = self::BAR . " boo\n";
}
雖然這不是問題的一部分,但應(yīng)該意識到實施的限制。以下將不工作,雖然它是靜態(tài)內(nèi)容(但可能在運行時被操縱):
class Foo {
public static $bar = "baz";
const HAZ = self::$bar . " boo\n";
}
// PHP Parse error: syntax error, unexpected '$bar' (T_VARIABLE), expecting identifier (T_STRING) or class (T_CLASS)
class Foo {
public static function bar () { return "baz";}
const HAZ = self::bar() . " boo\n";
}
// PHP Parse error: syntax error, unexpected '(', expecting ',' or ';'
總結(jié)
以上是生活随笔為你收集整理的php const 字符串,我可以使用字符串连接在PHP中定义一个类CONST吗?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php屏幕共享功能,利用无线投屏技术同屏
- 下一篇: php limit限流,php+redi