Skip to content

DDC-1025: Please repalce 'Doctrine\XXX\YYY' with '\Doctrine\XXX\YYY' in code and document #1615

Closed
doctrinebot opened this Issue Feb 9, 2011 · 13 comments

2 participants

@doctrinebot

Jira issue originally created by user wsyb:

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

@doctrinebot

Comment created by matthieu:

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.

Thanks

@doctrinebot

Comment created by k-fish:

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...

@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Comment created by k-fish:

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

@doctrinebot

Comment created by morfi:

Example (Entitymanager.php):

namespace Doctrine\ORM;

and

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

Result:
Doctrine\ORM\Doctrine\ORM\Configuration

Should be:

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

Or

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

Comment created by mvrhov:

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

@doctrinebot

Comment created by k-fish:

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?

@doctrinebot

Comment created by mridgway:

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.

@doctrinebot

Comment created by andrewmackrodt:

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.

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by @deeky666:

Fixed in commits:
3b259dc
bda9815

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.