here is the fatal error:
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"; ... } i am using php 7. why is this error showing? thanks
$_SERVER['HTTP_USER_AGENT'];is "run-time" information; and class propertydeclaration may include an initialization, but this initialization must be a constant value -- that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.global $user_agent;supposed to be? Is it something that should be passed as an argument to the method?