Is there a PHP DocBlock that I can use to refer to the magic-method property added after instantiation?

I am sending PHP objects to template files and would like to document at the top of my template file which properties of the object (using __get) are available and what they are, and make them available for code hinting.

Here is an example.

In my controller:

$obj = new Template("welcomePage"); $obj->title = "Welcome!"; $obj->render(); 

In my view / template:

 <?php /** * @var $obj Template The template data wrapper * @property $obj->title string The page header text /* ?> <h1><?php echo $obj->title; ?></h1> 

Is there something similar to this that will work? The way I did this will now not be automatically completed if I started typing $obj-> , that is, I (or a team member) need to refer to the top of the template to find every available property.

I was considering expanding the Template class for each type of template, but this seems like an unnecessary overhead since I could only add a row and an array to the page, and also create a separate class for each template, partial template and combination both seem a little silly.

Thanks ~

+7
php model-view-controller templates
source share
1 answer

Not. DocBlocks are document classes, not instances.

Having said that PHPDocumentor has a number of annotation tags at the class level to reveal some of the magic:

But it will not work for properties / methods dynamically added at runtime, since the properties differ between instances.

+7
source share

All Articles