如何告诉 PhpStorm 实施细节? (魔法方法)
我有一个对象“User”,它的属性的可访问性被声明为受保护,但可以通过魔术 __set 方法直接设置。
现在,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}; }
}
test.php
<?php
require "c.php";
$c1 = new c1();
var_dump($c1->a);
$c2 = new c2();
var_dump($c2->a);
和输出:
string 'c1' (length=2)
string 'c2' (length=2)
以及 它在 PhpStorm 中的样子:
我的目标:
要么让 PhpStorm“理解”设计,要么只是摆脱那些除了这个问题之外,到处都有烦人的红色标记,同时不会影响错误检测。
I have an object "User" that has attributes whose accessability is declared as protected but which can be set directly via a magic __set-method.
Now PhpStorm signals this apparent inconsistency with a big red column on the right side.
Is it possible to explain to PhpStorm what is going on so this is not shown as an error any more?
EDIT :
I use PhpStorm 2.1.4
okay here is some code that exemplifies the issue (together with the so far suggested workaround from Alexey which sadly doesn't do it for me):
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}; }
}
test.php
<?php
require "c.php";
$c1 = new c1();
var_dump($c1->a);
$c2 = new c2();
var_dump($c2->a);
and the output:
string 'c1' (length=2)
string 'c2' (length=2)
and how it looks like in PhpStorm:
my goal:
either having PhpStorm "understand" the design or just getting rid of those annoying red marks everywhere while not impairing the error detection apart from this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在可以在 PHPStorm 3 中使用:)
不幸的是,这是我们跟踪器中的一个开放请求,请参阅
http://youtrack.jetbrains.net/issue/WI-4468
现在避免此警告的唯一方法,就是将
@property
添加到$user的类声明中。 IEThis is now working in PHPStorm 3 :)
Unfortunately this is a open request in our tracker, see
http://youtrack.jetbrains.net/issue/WI-4468
The only way to avoid this warnings now, is to add
@property
to $user's class declaration. i.e.