Question about code completion

Hello everyone,

Sorry for my english (I speek french).

I'm using PHPStorn since 2 days...
And I have a question about code completion.

It's very usefull to me to use it because I have many objects with a lot of method.


In my php pages, if I do :

$user = new user();

Code completion is working fine when I type $user->...

But on my website, when someone is logged, I save the Object User on a Session Variable.
$_SESSION['current_user'] = $user;

On another page, if I type $_SESSION['current_user']->..., code completion doesn't work...

I understant that PHPStorn don't know that my session variable is an User Object...
Do you know if there is a workaround to "tell" to PHPStorn that this session variable is an User Object ?

Thanks

Francois

2 comments

Hi there,

Do you know if there is a workaround to "tell" to PHPStorn that this session variable is an User Object ?

There is no special comment/instruction that allows PhpStorm to provide type hinting to specific array key.

You can extract value of such array element into ordinary variable and then provide correct type hint with PHPDoc comment, like this:

$user = $_SESSION['current_user'];
/** @var User_Class $user */


.. but it does not work for specific array keys (this, or something similar, will NOT work)

/** @var User_Class $_SESSION['current_user'] */
0

Yeah !
It works like a charm !

Thank you very much.

I will buy a licence a the end of the trial.
This app is muuuuuch better than dreamweaver...

0

Please sign in to leave a comment.