How to have a hint type in PHP that defines the scope of a variable inside a template? (specifically PhpStorm)

I am looking for a comment on a document that will define the scope / context of the current php template. (similar to @var)

Example View class:

<?php class ExampleView { protected $pageTitle; public function __construct($title) { $this->pageTitle = $title; } public function render() { require_once 'template.php'; } } 

-

 <?php // template.php /** @var $this ExampleView */ echo $this->pageTitle; 

PHPStorm gives a validation error because access to $ pageTitle is protected.

enter image description here

Is there a hint of creating an area? Sort of:

 <?php // template.php /** @scope ExampleView */ // <---???? /** @var $this ExampleView */ echo $this->pageTitle; 
+6
source share
1 answer

Unfortunately, you cannot - there is no such tag (in general or specific to PhpStorm).

Let them hope that they (JetBrains developers) will do something about it: http://youtrack.jetbrains.com/issue/WI-11022 - vote / comment / etc., and if he gets a lot more votes, which we can see in the near future (right now, "soon" away).

+1
source

Source: https://habr.com/ru/post/918703/


All Articles