views:

35

answers:

2

What are useful php annotations for Netbeans code completition? I'm already familiar with @return, @param and @throws, but are there any others?

For example, can I set which keys will returned ArrayObject have? In this example, I'd like IDE to suggest me foo and bar after I type get()->. Is it even possible? If so, how?

/**
 * @ ???
 */
function get() {
    $res = new \ArrayObject();
    $res->foo = 1;
    $res->bar = 2;
    return $res;
}
+2  A: 

Have a look at phpDocumentor. That's where those annotations come from. It's kind of like Javadoc, but for PHP.

Daniel Egeberg
Thanks, that's nice resource. For a start. However, I did not found the solution to my problem there. Neither property nor any else seems to do what I need.
Mikulas Dite
+1  A: 

Sorry to say in your case there is no way to get this done in any PHP IDE :-(

The only possibilty is to inherit ArrayObject in your own class to get this done but I think you want to set different properties at runntime...

/**
 * @property integer foo
 * @property integer bar
 */
class MyArrayObject extends \ArrayObject
{
}

/**
 * @return MyArrayObject
 */
function get() {
    $res = new MyArrayObject();
    $res->foo = 1;
    $res->bar = 2;
    return $res;
}
Timo
Thanks. I was afraid so, yet there's no other possibility.
Mikulas Dite