这是致命错误:
致命错误:常数表达式包含无效操作
我在此代码中遇到致命错误:
<?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";
...
}
我正在使用PHP7。为什么显示此错误?谢谢
而不是这样做
<?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";
...
}
希望它有帮助