当静态调用类的方法时,我可以在构造函数中获得变量吗?


Can I get variable in constructor when statically call method of class?

我可以检查__construct中的$param值并在self::$param中设置新值吗?

Class::method($param);
class Class {    
    public function __construct() {

    }
    public static function method($param) {

    }
}

如果你有一个类的静态成员,就可以这样做

class Class 
{    
    public static $member;
    public function __construct() {
          // Here you can get or set the static::$member
    }
    public static function method($param = static::$member) {

    }
}

现在,如果你调用带有参数的方法,它接受参数的值,否则它接受static::$param

的值
Class::$member = 123;
Class::method();  // $param = 123
Class::method(456); // $param = 456