[DDC-1025] Please repalce 'Doctrine\XXX\YYY' with '\Doctrine\XXX\YYY' in code and document Created: 09/Feb/11  Updated: 01/Apr/14  Resolved: 01/Apr/14

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: Documentation, DQL, Mapping Drivers, ORM, Tools
Affects Version/s: 2.0.1
Fix Version/s: 2.1, 2.2
Security Level: All

Type: Improvement Priority: Major
Reporter: ben yan Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 7
Labels: None


It will help us use the namespace and code autocomplete in some IDE.

Comment by Matthieu Napoli [ 08/Apr/11 ]

Hi, do you have any more information about this ?

I'm confused because the php documentation uses the Doctrine\XXX way, and everywhere I've seen, it is used like that.


Comment by Karsten Dambekalns [ 11/Apr/11 ]

The issue is simple and logical.

When an IDE (I am using PhpStorm and it does it like this) sees a namespace in a file, upon seeing namespaces afterwards, it sees them as absolute if they have a leading backslash, or relative when it does not. This affects the resolution of classes for type navigation, code inspection, ... The same rules as for actual PHP code should be used within comments.

Here is an example:

namespace Foo;

class Bar {

   * @var Baz
  protected $baz;

   * @var \Quux
  protected $quux;


The IDE will think $baz is \Foo\Baz and $quux will be seen as being \Quux. Now if you have some reference to Doctrine here, and it was relative, the IDE would assume it's \Foo\Doctrine\...

Comment by Benjamin Eberlei [ 11/Apr/11 ]

Well yes, but since all our code examples have no leading namespace argument this means the code is in the default namespace, making Doctrine\XXX\YY a relative namespace that is actually valid.

Comment by Karsten Dambekalns [ 11/Apr/11 ]

Yes, but the source code docblocks are what is meant here as far as I am concerned.

Comment by Andrey Kolyshkin [ 13/May/11 ]

Example (Entitymanager.php):

namespace Doctrine\ORM;


  * The used Configuration.
  * @var Doctrine\ORM\Configuration
   private $config;


Should be:

  * The used Configuration.
  * @var Configuration
   private $config;


  * The used Configuration.
  * @var \Doctrine\ORM\Configuration
   private $config;
Comment by Miha Vrhovnik [ 27/May/11 ]

Why don't you take this to the PhpStorm tracker as it surely is a bug in IDE?

Comment by Karsten Dambekalns [ 27/May/11 ]

Miha, what makes you think it's an IDE bug? In a class in namespace Foo another class named Bar is \Foo\Bar, but \Bar is \Bar. Why is it a bug if the IDE follows the namespace resolution rules?

Comment by Michael Ridgway [ 11/Jul/11 ]

The issue is that PHPStorm and NetBeans have different class resolution rules. I also use PHPStorm and most of Doctrine does not resolve auto-completion correctly because of this issue.

I'd be willing to work on this if it would be accepted.

Comment by Andrew Mackrodt [ 29/Sep/11 ]

I've been evaluating PhpStorm and also came across this issue; I believe the problem is due to Doctrine rather than being a bug with the IDE although it would be nice if PhpStorm would assume namespaces are absolute if they're not resolved upon an initial lookup.

I created a quick c# app to append the beginning forward slash to any @var or @return attributes within Doctrine's source. It's working for me with Doctrine 2.1.2 and PhpStorm (IntelliJ): http://pastebin.com/4HxiWvJA - hopefully this will be of use for anyone else using these IDEs;. Note: the application doesn't detect multiple line annotations although the only one I'm aware of is the getAST method in Doctrine\ORM\Query.php.

Comment by Benjamin Eberlei [ 13/Dec/11 ]

This issue is referenced in Github Pull-Request GH-215

Comment by Benjamin Eberlei [ 13/Dec/11 ]

This issue is referenced in Github Pull-Request GH-216

Comment by Steve Müller [ 01/Apr/14 ]

Fixed in commits:

Generated at Wed Oct 14 00:01:13 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.