This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 238871

Summary: Method return class name from string
Product: php Reporter: PHPGeek
Component: EditorAssignee: Ondrej Brejla <obrejla>
Status: NEW ---    
Severity: normal    
Priority: P1    
Version: 7.4   
Hardware: PC   
OS: Linux   
Issue Type: ENHANCEMENT Exception Reporter:

Description PHPGeek 2013-11-27 12:10:00 UTC
Hello,

This is (in my opinion), one of the most important features that NetBeans MUST have.
Using Doctrine or many many other APIs allow developers to have some methods like :

<?php

class EntityManager {
  /**
   * @return $classname
   */
  public function find($classname) {
    return new $classname;
  }
}

?>

so that when you call $entityManager->find("MyClass"); it would return an instance of MyClass, there's no such thing as @return $classname (or return instance of class that is a string). It's so boring not having the pop-up that shows the available methods from the class we've passed in variables.

I know it must be hard, but it's just resolving a string to a class name, and then suggesting the available internal methods and stuff.
Comment 1 Xenos 2017-02-17 15:31:31 UTC
I think this cannot be resolved, because you could do a

$entityManager->find($_POST['ugly']);

There, what's the returned class? (Year, NEVER do such thing, but you get the idea: the name in the call can be dynamic).

If you want to get auto-completion in the calling, you should just use the PHPDoc syntax:

/* @var $myvar \vendor\namespace\MyClass */
$myvar = $entityManager->find("MyClass);

There, NB 8.2 will know that the $myvar variable contains a MyClass instance, and it will provide all required hints.

If that suits your needs (after all these years!), tell us so this bug can be closed.