【问题标题】:Strict standards non static method严格标准的非静态方法
【发布时间】:2015-05-08 00:56:24
【问题描述】:

我想修正这个错误:

严格标准:非静态方法 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 上调用静态

【问题讨论】:

    标签: php standards anonymous-function strict


    【解决方案1】:

    问题:

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

    解决方案:

    您可以更新 Gpf_Settings_Regional 类

    改变

    public function getInstance()
    

    public static function getInstance()
    

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

    How to eliminate php5 Strict standards errors?

    【讨论】:

      【解决方案2】:

      如果我觉得不错,它已经由脚本制作了

      */ 私有静态 $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()->getThousandsSeparator()); $this->addValue(Gpf_Settings_Gpf::REGIONAL_SETTINGS_DECIMAL_SEPARATOR, Gpf_Settings_Regional::getInstance()->getDecimalSeparator()); $this->addValue(Gpf_Settings_Gpf::REGIONAL_SETTINGS_DATE_FORMAT, Gpf_Settings_Regional::getInstance()->getDateFormat()); $this->addValue(Gpf_Settings_Gpf::REGIONAL_SETTINGS_TIME_FORMAT, Gpf_Settings_Regional::getInstance()->getTimeFormat());

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

      【讨论】:

        猜你喜欢
        • 2013-03-31
        • 2013-05-08
        • 2013-01-08
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多