我有一个对象“用户”,该对象具有属性,其可访问性被声明为受保护,但可以通过魔术 __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}; }
}
测试.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 “理解”设计,要么只是摆脱那些恼人的红色标记,而不影响除此问题之外的错误检测。