I'm sending PHP objects to template files and would love to document at the top of my template file what properties of the object (using __get) are available and what they are and make them available for code-hinting.
Here's 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 would work? The way I have it now would not auto-complete if i started typing $obj->
, meaning I (or a team member) needs to reference the top of the template to find each available property.
I was considering extending the Template class for each template type, but that seems like unnecessary overhead since I might only add a string and an array per page, and to create a separate class for every template, partial template, and combination of both seems a little silly.
Thank you~
No. DocBlocks document classes, not instances.
Saying that, PHPDocumentor has number of class-level annotation tags to expose some of the magic:
But it wouldn't work for properties/methods dynamically added at runtime since properties differ between instances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With