Sometimes, especially when dealing with variations of factory pattern, single method (namely factory()) can return objects of different types, so NetBeans is unable to guess the exact type of returned instance and as such cannot auto-complete. Indeed, you can setup return type using phpDoc syntax:
but that doesn’t work if returned objects are specifications of more general abstract class (exactly the case with factory).
As it turned out, you can easily resolve this issue – just document your variable with @var, before calling factory() method:
The good news, you can use this method in any scope – it just works I love NetBeans!!
UPD: Well, actually NetBeans seems to be picky of scope – as reported by others (and confirmed by myself).
UPD1: Actually NetBeans handles this quite well, just use vdoc