开发者

How to tell PhpStorm about implementation details? (magic methods)

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.

How to tell PhpStorm about implementation details? (magic methods)

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;

开发者_Go百科    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:

How to tell PhpStorm about implementation details? (magic methods)

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.


This 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.

/**
 * @property $name string
 */
class User {
    protected $name; 
}
$user = new User();
$user->name = "me";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜