PHP致命错误:常量表达式包含无效操作 [英] PHP Fatal error: Constant expression contains invalid operations
本文介绍了PHP致命错误:常量表达式包含无效操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是致命错误:
致命错误:常量表达式包含无效运算
Fatal error: Constant expression contains invalid operations
此代码中出现致命错误:
I get a fatal error in this code:
<?php
class InfoClass {
private $user_agent = $_SERVER['HTTP_USER_AGENT']; // error is on this line
public static function getOS() {
global $user_agent;
$os_platform = "Unknown OS Platform";
...
}
我正在使用php 7 。为什么显示此错误?谢谢
i am using php 7. why is this error showing? thanks
推荐答案
请改为这样做
<?php
class InfoClass {
private $user_agent;
public function __construct(){
$this->user_agent = $_SERVER['HTTP_USER_AGENT']; // error is on this line
}
public static function getOS() {
global $user_agent;
$os_platform = "Unknown OS Platform";
...
}
希望有帮助
这篇关于PHP致命错误:常量表达式包含无效操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文