How to have type hinting in PHP that specifies variable scope inside of a template? (specifically PhpStorm)

Posted by Lance Rushing on Stack Overflow See other posts from Stack Overflow or by Lance Rushing
Published on 2012-06-21T21:11:51Z Indexed on 2012/06/21 21:16 UTC
Read the original article Hit count: 229

Filed under:
|

I'm looking for a doc comment that would 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 an inspection error because the access on $pageTitle is protected.

enter image description here

Is there a hint to give scope? Something like:

<?php
// template.php 
/** @scope ExampleView */ // <---????

/** @var $this ExampleView */
echo $this->pageTitle;

© Stack Overflow or respective owner

Related posts about php

Related posts about phpstorm