$this->request is red underlined in Trait
Hello,
In a Laravel 5.2 project I have a BaseController like this:
class BaseController extends Controller
{
protected $messages;
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
}
All other Controllers inherit from this
Then I have a Trait that I use in some Controller(s)
trait SortableTrait
{
public function _sortable($default_sort, $allowed_sort, $default_order = 'asc')
{
$allowed_order = ['asc', 'desc'];
$sort = in_array($this->request->get('sort'), $allowed_sort) ? $this->request->get('sort') : $default_sort;
$order = in_array($this->request->get('order'), $allowed_order) ? $this->request->get('order') : $default_order;
$params = compact('sort', 'order'); // create the array
$this->request->merge($params); // for default icon on load
return $params;
}
}
Well, the part:
$this->request->...
is treated as a error in PHPStorm (I get a 'Member has protected access' warning when I hover the 'request' word) and the file / folder are red underlined. Anyway, the application works as expected.
Problem is gone when I change:
protected $request;
to
public $request;
but I would avoid this...
So, is this a PHPStorm bug? Is there a way to avoid the annoying red underline?
Thanks
请先登录再写评论。
Hi Ivan,
Please try the latest EAP, is the issue actual there?
https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program
I have the same issue using EAP PhpStorm-162.646.18
A trait can expose members (properties and methods) to the class that uses it, and also can use the methods and properties from the class.
Looks like the problem is that the trait can only access public members and not protected or private.
This is a case that shows the problem.
(1) TSomeOne shows the error until is used inside AFoo
(2) TSomeTwo shows the error until the annotation @mixin is set
This is https://youtrack.jetbrains.com/issue/WI-30855
Please vote for it to move it in a queue and receive notifications regarding the progress of the issue.
Has anyone solved this issue?
Just found that adding a docblock with `@property Type $var` solves ("hides") the inspection error.