Parse error: syntax error, unexpected '('
This question already has an answer here:
Your problem is that you are trying to define an static variable with self static function. Since you have never instantiated the class (static) and you are calling an static variable, you cannot call a self static function.
If I copy paste your code and run it with PHP 7 it gives other error:
Fatal error: Constant expression contains invalid operations in C:inetpubwwwroottest.php on line 4
To solve your problem, use this:
<?php
class Helper {
public static $app_url;
public static function Init() {
self::$app_url = self::getServerUrl();
}
public static function getServerUrl(){
global $cfg; // get variable cfg as global variable from config.php Modified by Gentle
$port = $_SERVER['SERVER_PORT'];
$http = "http";
if($port == "80"){
$port = "";
}
if(!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on"){
$http = "https";
}
if(empty($port)){
return $http."://".$_SERVER['SERVER_NAME']."/".$cfg['afn'];
}else{
return $http."://".$_SERVER['SERVER_NAME'].":".$port."/".$cfg['afn'];
}
}
}
Helper::Init();
链接地址: http://www.djcxy.com/p/69490.html
下一篇: 解析错误:语法错误,意外'('