我正在使用Xamppp在localhost上测试我的PHP应用程序,一切都很好,但是当我将它导出到真实服务器时,它不再起作用了。我发现这是因为我的服务器不支持后期静态绑定。 我的服务器版本为 5.2.17 。
我收到此错误。
<b>Parse error</b>: syntax error, unexpected T_STATIC in <b>/home/storage/f/9d/09/meuplacar/public_html/filme/work/class_lib.php</b> on line <b>555</b><br />
我只是在我构建的Util类中使用static
关键字。你建议我改变这种方法:
的Util
class Util
{
private static $initialized = false;
private static function initialize()
{
if (self::$initialized)
return;
self::$initialized = true;
}
public static function getHoursAndMinutesFromTime($time) {
self::initialize();
$pieces = explode (":", $time);
$output = "";
$output = $pieces[0] . ":" . $pieces[1];
return $output;
}
}
对于独特的门面实例
的Singleton
abstract class Singleton {
protected static $_instance = NULL;
/**
* Prevent direct object creation
*/
final private function __construct() {
}
/**
* Prevent object cloning
*/
final private function __clone() {
}
/**
* Returns new or existing Singleton instance
* @return Singleton
*/
final public static function getInstance(){
if(null !== static::$_instance){
return static::$_instance;
}
static::$_instance = new static();
return static::$_instance;
}
}
class Facade extends Singleton {
public function retrieveAllWorkdays()
{
$array = DB::selectAllWorkdays();
return Util::constructWorkdaysArray($array);
}
答案 0 :(得分:0)
后期静态绑定仅在php 5.3.0及更高版本中可用:http://php.net/manual/en/language.oop5.late-static-bindings.php