【问题标题】:How to call static function from constructor in same class PHP?如何从同一类 PHP 中的构造函数调用静态函数?
【发布时间】:2010-12-26 16:35:03
【问题描述】:

你好我想问一下: 如何从 PHP 同类的构造函数中调用静态函数?

我有:

public function __construct()

我需要调用这个函数

private function _regenerateThumbnails($type = 'all', $deleteOldImages = false)

在构造函数中。

在 PHP 中是否可以,如果可以,如何实现?

感谢您的建议。

【问题讨论】:

    标签: php function static constructor


    【解决方案1】:

    首先,您应该显式声明该方法为静态的,如下所示:

    private static function _regenerateThumbnails($type = 'all', $deleteOldImages = false)
    

    要在构造函数中调用它,请使用 self 关键字:

    public function __construct() {
        // Pass arguments from your constructor to your method
        // where appropriate
        self::_regenerateThumbnails();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 2014-03-12
      • 2018-09-25
      • 2023-04-03
      相关资源
      最近更新 更多