Detecting variables using __set and __get Follow
I have a class that uses the __set and __get magic methods to handle most of the variables, so that any other class can easily add new variables. However, I can not seem to get PHPStorm to recognize these variables, and want to find out for sure if this is in fact possible.
This is how the template class is documented:
class Template {
private $_vars = array();
public function __construct() {
}
/**
* Get allows for the retrieval of stored values, by index
*
* @param $index
*
* @internal param \index $String The name of the variable to be retrieved
* @return String The value of the requested variable
*/
public function __get ($index) {
return $this->_vars[$index];
}
/**
* Set allows for the storage of values. Will not allow the database connection to be overwritten.
*
* @param $index
* @param $value
* @return bool
*
* @internal param \index $String The name of the variaable to store
*
* @internal param \value $mixed The value of the variable
*/
public function __set ($index, $value) {
if ($index == 'dbc') return FALSE;
$this->_vars[$index] = $value;
return TRUE;
}
}
In the other class, I call it as follows:
$this->template = new Template();
$this->template->something = $something //->something is marked as undefined
Is there something wrong in the comments or somewhere else that needs to be changed? Most of the docs that are shown were autogenerated by PHPStorm.
Please sign in to leave a comment.
Hello William,
Sorry for delay.
You need to define every 'magic' property via 'property' PHPDoc tag. See http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.property.pkg.html
An example:
Thank you for feedback!