我正在尝试访问函数中的类中的变量:
class google_api_v3 {
public static $api_key = 'this is a string';
function send_response() {
// access here $api_key, I tried with $this->api_key, but that works only on private and that variable I need also to access it outside the class that is why I need it public.
}
}
function outside_class() {
$object = new google_api_v3;
// works accessing it with $object::api_key
}
最佳答案
使用值/方法(包括静态方法)的通用方式里面 类(class)是self::
echo self::$api_key;
关于php - 在函数php中访问类内的公共(public)静态变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661615/