做暧暖ox网站,网站开发排期表模板,wordpress什么样子,如何用网页制作网站const变量经常被当做常量用在php的类中#xff0c;隐含的意思是这个变量是常量#xff0c;不能被修改。编译器会自动检测#xff0c;如果被赋值会被提示错误警告。 正确实例1#xff1a; ?php
class test
{const ERRNO 100;
}
echo test::ERRNO.\n; 输出…const变量经常被当做常量用在php的类中隐含的意思是这个变量是常量不能被修改。编译器会自动检测如果被赋值会被提示错误警告。 正确实例1 ?php
class test
{const ERRNO 100;
}
echo test::ERRNO.\n; 输出 100 错误示范1const常量被赋值编译器提示错误 ?php
class test
{const ERRNO 100;
}
test::ERRNO 10;
echo test::ERRNO.\n; 输出 PHP Parse error: syntax error, unexpected 错误示范2const常量被当做变量来定义 ?php
class test
{const $ERRNO 100;
} 输出 PHP Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING 错误示范3const常量被赋值为数组型 ?php
class test
{const ERRNO array(100);
} 输出 PHP Fatal error: Arrays are not allowed in class constants 至于为什么const常量不能被定义为array数组型 php官方文档给出的解释是尽管这有可能实现但会产生一些未知的风险和结果所以不推荐。支持的类型为标量类型(scalar data:(boolean, integer, float and string)) 更多细节参考http://www.php.net/manual/en/language.constants.syntax.php转载于:https://www.cnblogs.com/helww/p/3596979.html