php PhpStorm 字段通过魔术方法访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25578649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:53:54  来源:igfitidea点击:

PhpStorm Field accessed via magic method

phpcodeigniterphpstorm

提问by Sizzling Code

I have ignited datatables Library in my CodeIgniter library folder.

我在我的 CodeIgniter 库文件夹中点燃了数据表库。

Some Code from Library

库中的一些代码

class Datatables
{
    /**
     * Global container variables for chained argument results
     *
     */
    protected $ci;
    protected $table;
    protected $distinct;
    protected $group_by;
    protected $select         = array();
    protected $joins          = array();
    protected $columns        = array();
    protected $where          = array();
    protected $filter         = array();
    protected $add_columns    = array();
    protected $edit_columns   = array();
    protected $unset_columns  = array();

    /**
     * Copies an instance of CI
     */
    public function __construct()
    {
        $this->ci =& get_instance();
    }

Then I called the library in model

然后我在模型中调用了库

class Common_Model extends MY_Model{

    function __construct(){
        parent::__construct();
        $this->load->library('Datatables.php');
    }

then I tried to call the library functions

然后我尝试调用库函数

function select_fields_joined_DT($data, $PTable, $joins = '', $where = '', $addColumn = '',$unsetColumn='')
{
    /**
     *
     */
    $this->datatables->select($data);
    if ($unsetColumn != '') {
        unset_column($unsetColumn);
    }
        $this->datatables->from($PTable);
    if ($joins != '') {
        foreach ($joins as $k => $v) {
            //$this->datatables->join($v['table'], $v['condition'], $v['type']);
        }
    }

    if ($addColumn != '') {
        $this->datatables->add_column("Actions", $addColumn);
    }

    $result = $this->datatables->generate();
    return $result;
}

and everything works fine, except that the phpstorm shows me this error:

一切正常,除了 phpstorm 显示了这个错误:

Field Accessed via magic method

enter image description here

在此处输入图片说明

I tried to remove this error with document comments but can't figure out how can I do that.. any help will be appreciated.

我试图用文档注释删除这个错误,但不知道我该怎么做..任何帮助将不胜感激。

回答by chrisan

If you want to remove this without document comments you can uncheck Notify about access to a field via magic methodwhich is found in

如果您想在没有文档注释的情况下删除它,您可以取消选中Notify about access to a field via the magic methodwhich is found in

Project Settings> Inspections> PHP> Undefined> Undefined field

项目设置>检查> PHP>未定义>未定义字段

Notify about access to a field via magic method

通过魔术方法通知访问字段

回答by Emile Bergeron

As mentioned by LazyOnein the question comments:

正如LazyOne在问题评论中所提到的

You have to declare them via @propertyin PHPDoc comment that belongs to that class.

您必须通过@property属于该类的 PHPDoc 注释来声明它们。

/**
 * @property string $bar
 */
class Foo {

    public function __get($name) {
        if ($name == 'bar') {
            return 'bar';
        }
        return NULL;
    }
}

Snippet from Dmitry Dulepov's article "Quick tip: magic methods and PhpStorm".

摘自 Dmitry Dulepov 的文章“快速提示:魔术方法和 PhpStorm”