如何告诉PhpStorm实施细节?(魔术方法)

Raf*_*ael 11 phpstorm

我有一个对象"User",它具有可访问性被声明为受保护但可以通过magic __set-method直接设置的属性.

在此输入图像描述

现在,PhpStorm发出了与右侧红色大柱明显不一致的信号.

是否有可能向PhpStorm解释发生了什么,所以这不再显示为错误?


编辑:

我使用PhpStorm 2.1.4

好的,这里有一些代码可以解释这个问题(连同到目前为止Alexey的建议解决方法,遗憾的是它没有为我做):

c.php:

<?php
/**
 * @property mixed $a
 */
class c1
{
    protected $a;

    public function __construct() { $this->a = __CLASS__; }

    public function __get($n) { return $this->{$n}; }
}

/**
 * @property $a mixed
 */
class c2
{
    protected $a;

    public function __construct() { $this->a = __CLASS__; }

    public function __get($n) { return $this->{$n}; }
}
Run Code Online (Sandbox Code Playgroud)

test.php的

<?php
require "c.php";

$c1 = new c1();
var_dump($c1->a);

$c2 = new c2();
var_dump($c2->a);
Run Code Online (Sandbox Code Playgroud)

和输出:

string 'c1' (length=2)
string 'c2' (length=2)
Run Code Online (Sandbox Code Playgroud)

以及在PhpStorm中的样子:

在此输入图像描述

我的目标:

要么PhpStorm"理解"设计,要么只是摆脱那些烦人的红色标记,而不是在不影响错误检测,除了这个问题.

Ale*_*nko 8

现在正在PHPStorm 3中工作:)

不幸的是,这是我们跟踪器中的一个开放请求,请参阅 http://youtrack.jetbrains.net/issue/WI-4468

现在避免此警告的唯一方法是添加@property到$ user的类声明.即

/**
 * @property $name string
 */
class User {
    protected $name; 
}
$user = new User();
$user->name = "me";
Run Code Online (Sandbox Code Playgroud)