drsl90685154 2011-09-28 07:46
浏览 58

PHP中的静态替代<b>解析错误</ b>:语法错误,<b>中的意外T_STATIC

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 version 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);
    }
  • 写回答

1条回答 默认 最新

  • dpyln64620 2011-09-28 08:00
    关注

    Late static bindings only are available in php 5.3.0 and later: http://php.net/manual/en/language.oop5.late-static-bindings.php

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类