Static Alternative in PHP for <b>Parse error</b>: syntax error, unexpected T_STATIC in <b>
I was testing my PHP application on localhost with Xamppp and everything was just fine, but when I exported it to a real server, it does not work anymore. I found out that it is because my server does not support late static binding. My server has vers开发者_运维问答ion 5.2.17.
I get this error.
<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 />
I just use the static
keyword in a Util class I built. What would you suggest for me to change this kind of methods:
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;
}
}
And for a Unique Facade Instance
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);
}
Late static bindings only are available in php 5.3.0 and later: http://php.net/manual/en/language.oop5.late-static-bindings.php
精彩评论