类常量作为数组的键 [英] Class constant as array key
本文介绍了类常量作为数组的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请看看下面code:
...
类LanguageResources {
常量SESSION_LANGUAGE_KEY ='郎'; 公共静态功能getLanguageSettingsFilePath(){ 如果(使用isset($ _ GET [LanguageResources :: SESSION_LANGUAGE_KEY])){
....
我获得最后一行的PHP错误信息。有什么问题通过常数值数组索引访问?
注意:未定义的常量SESSION_LANGUAGE_KEY用途 - 假定... languages.phpSESSION_LANGUAGE_KEY第17行
解决方案
在类中的常数定义,必须引用它作为自:: SESSION_LANGUAGE_KEY
代替
Please take a look at following code:
...
class LanguageResources {
const SESSION_LANGUAGE_KEY = 'lang';
public static function getLanguageSettingsFilePath() {
if (isset($_GET[LanguageResources::SESSION_LANGUAGE_KEY])) {
....
I obtain an PHP error message for the very last line. What's wrong with array index access via constant value?
Notice: Use of undefined constant SESSION_LANGUAGE_KEY - assumed 'SESSION_LANGUAGE_KEY' in ...languages.php on line 17
解决方案
Inside the class that the constant was defined in, you must reference it as self::SESSION_LANGUAGE_KEY
instead.
这篇关于类常量作为数组的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文