简体   繁体   中英

PHPDoc for property of object

Is is possible (for type hinting purposes) to indicate the class of an object's property? The final product of the code works as expected, but, type hinting does not. For example, the following shows what I am trying to accomplish but that does not work:

    /* @var $this->view \app\components\View */
    $this->view->title = 'Title here';

All I have ever seen were references to @var $this or similar, but never a property of the $this object. If this is possible, what am I missing?

Yes - you must apply the PHPDoc annotation where you declare the property in the class:

class Foo
{
    /* @var \app\components\View $view*/
    public $view;

    public function __construct()
    {
          $this->view->title = 'Title here';
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM