严格的标准非静态方法

时间:2015-03-06 12:07:32

标签: php standards anonymous-function strict

我想修复此错误:

  

严格标准:非静态方法   不应静态调用Gpf_Settings_Regional :: getInstance(),   从第39行的不兼容上下文中假设$ this

产生它的代码:

$this->addValue(Gpf_Settings_Gpf::REGIONAL_SETTINGS_DECIMAL_SEPARATOR, 
Gpf_Settings_Regional::getInstance()->getDecimalSeparator());

我知道这是PHP 5.3的方法,但我在共享主机上有5.4,需要在PHP 5.4上调用static

2 个答案:

答案 0 :(得分:2)

<强>问题:

您正在静态访问非静态方法,并且已打开严格的标准错误报告。

<强>解决方案:

您可以更新Gpf_Settings_Regional类

变化

public function getInstance()

public static function getInstance()

如果您无法更改该类,则可以更改错误报告并更改严格标准错误的报告,但最好是改进代码。

How to eliminate php5 Strict standards errors?

答案 1 :(得分:0)

如果我看得很清楚它已经由脚本

制作了

* /     private static $ instance;

public static function create(Gpf_Application $application) {
    setlocale(LC_ALL, 'en.UTF-8');
    self::$instance = $application;
    self::$instance->registerRolePrivileges();
    self::$instance->initLogger();
    self::$instance->addSmartyPluginsDir();
    $timezone = Gpf_Settings_Gpf::DEFAULT_TIMEZONE;
    try {
        $timezone = Gpf_Settings::get(Gpf_Settings_Gpf::TIMEZONE_NAME);
    } catch (Gpf_Exception $e) {
        Gpf_Log::error('Unable to load timezone: %s - using default one.', $e->getMessage());
    }
    if(false === @date_default_timezone_set($timezone)) {
        Gpf_Log::error('Unable to set timezone %s:', $timezone);
    }
}

public function getDefaultLanguage() {
    return 'en-US';
}

/**
 * @return Gpf_Application
 */
public static function getInstance() {
    if(self::$instance === null) {
        throw new Gpf_Exception('Application not initialize');
    }
    return self::$instance;
}

这是问题的一部分

抽象类Gpf_ApplicationSettings扩展了Gpf_Object {

/**
 * @var Gpf_Data_RecordSet
 */
private $recordSet;

const CODE = "code";
const VALUE = "value";

protected function loadSetting() {
    $this->addValue("theme", Gpf_Session::getAuthUser()->getTheme());
    $this->addValue("date_time_format", 'MM/d/yyyy HH:mm:ss');
    $this->addValue("programVersion", Gpf_Application::getInstance()->getVersion());
    $this->addValue(Gpf_Settings_Gpf::NOT_FORCE_EMAIL_USERNAMES, Gpf_Settings::get(Gpf_Settings_Gpf::NOT_FORCE_EMAIL_USERNAMES));

    $quickLaunchSettings = new Gpf_Desktop_QuickLaunch();
    $this->addValue(Gpf_Desktop_QuickLaunch::SHOW_QUICK_LAUNCH, $quickLaunchSettings->getShowQuickLaunch());

    $this->addValue(Gpf_Settings_Gpf::REGIONAL_SETTINGS_THOUSANDS_SEPARATOR,

Gpf_Settings_Regional ::的getInstance() - &GT; getThousandsSeparator());         $ this-&gt; addValue(Gpf_Settings_Gpf :: REGIONAL_SETTINGS_DECIMAL_SEPARATOR,Gpf_Settings_Regional :: getInstance() - &gt; getDecimalSeparator());         $ this-&gt; addValue(Gpf_Settings_Gpf :: REGIONAL_SETTINGS_DATE_FORMAT,Gpf_Settings_Regional :: getInstance() - &gt; getDateFormat());         $ this-&gt; addValue(Gpf_Settings_Gpf :: REGIONAL_SETTINGS_TIME_FORMAT,Gpf_Settings_Regional :: getInstance() - &gt; getTimeFormat());

    Gpf_Plugins_Engine::extensionPoint('Core.loadSetting', $this);
}