我想一个类中访问一个变量的函数:访问公共静态变量
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
}
外:google_api_v3 :: $ API_KEY也应努力?和内部使用:self :: $ api_key或static :: $ api_key – 2014-09-04 09:18:38
@RaphaelMüller是的,工作。 – user3467855 2014-09-04 09:21:34
@ user3467855顺便说一句,因为你似乎认为它是关于可变的可见性,所以你的变量是公有的还是私有的这一事实与你的问题无关。我不明白“它只适用于私人”如何使用$ this-> api_key,它不应该工作。 – Sugar 2014-09-04 09:42:04