I use Eclipse for PHP development and really appreciate the productivity gain. I am a javadoc comment zealot too because the code hinting and autocompletion really speed things up and reduce errors in code.
Can anyone tell me how to write a javadoc comment for @return when my function returns an array of class objects? When I iterate through the array, I want Eclipse to give me code hints for each returned object.
For example, here's one of my class functions in a class called BCDataObject:
/**
* Fetches all data records from the db table.
* @param CI_DB_driver $db CodeIgniter JDatabase object to access database
* @return multitype:BCDataObject
*/
public static function fetch_all($db) {
$query = $db->get(static::DATABASE_TABLE);
$results = array();
foreach ($query->result_array() as $record) {
$results[] = new static($db, $record);
}
return $results;
} // fetch_all()
I know that Eclipse is smart enough to recognize that the function returns a collection of objects because it automatically created this boilerplate javadoc when I first created the javadoc block by typing a slash and two asterisks and hitting return. In fact, this is the doc block auto-created by eclipse:
/**
*
* @param unknown_type $db
* @return multitype:BCDataObject
*/
The problem I have is that when I go to a place where I am using this code, I can use my function to get the array of objects but when I do a foreach loop on the result, Eclipse doesn't seem to know the type of the objects I am iterating so I don't get autocomplete or code hinting. For example, in this block of code:
$v = BCDataObject::fetch_all($this->db);
foreach($v as $user) {
echo $user . "<br>";
}
Eclipse doesn't give me code hints or autocomplete for the var $user -- for some reason it fails to recognize that each element of $v will be of type BCDataObject.
Can anyone tell me how to create my javadoc so I get this type of code hinting? Is it possible? If I could get that working, it would rule.