php类中的私有静态变量 [英] Private static variables in php class

查看:216
本文介绍了php类中的私有静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个类通常通过 var_dump print_r 运行。

I have a few classes that are often run through var_dump or print_r.

在这些类中,我有一些变量是对其他大型对象的引用,这些对象只有每个对象的一个​​实例,并且只能在类中使用(在类外面有它们自己的引用类)我不希望这些类打印在输出中,所以我已经声明它们 private static 这是工作正常。

Inside these classes I have a few variables that are references to other, rather large objects that only ever has one instance of each and are only used inside the classes (outside the classes have their own reference to these classes) I do not wish these classes printed in the output, so I have declared them as private static which is working fine.

但是我的IDE(PHPstorm)是通过当我通过 self ::访问它们时,成员具有私有访问 $ ci-> ...

But my IDE (PHPstorm) is flicking up an error-level alert with Member has private access when I access them through self::$ci->...

我想知道这是否是IDE中的错误,突出显示,因为它可能是一个错误它是静态的,但没有什么外面的类可以访问它,为什么要这样做?),还是因为实际上有一些语法错误呢?

I am wondering if this is a bug in the IDE, highlighting because it's probably a bug (aka it's static but nothing outside the class can access it, why would you want to to do that?), or because there is actually something syntactically wrong with it?

这里的例子是类的一部分,
注意 =& get_instance(); 返回对代码Igniter超级对象的引用

As an example here is part of the class, Note that =& get_instance(); returns a reference to the Code Igniter super object

private static $ci = null;

public function __construct(){
    self::$ci = self::$ci =& get_instance();
}

public function product() {
    if ($this->product == null) {
        self::$ci->products->around($this->relative_date);
        $this->product = self::$ci->products->get($this->product_id);
    }
    return $this->product;
}


推荐答案

c> c> c> product()方法访问私有成员 self :: $ ci 。您的IDE认为此方法可以在任何地方访问,并检测与私有静态成员 $ ci 的冲突。

In your product() method you're trying to access the private member self::$ci. Your IDE thinks that this method can be accessed anywhere, and detects a conflict with the private static member $ci.

这篇关于php类中的私有静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆