annotations: PHP7 Grouped Use Statements ignored

When I use the new PHP7 grouped use statements feature, Doctrine doesn’t use the namespace to import the annotation.

For example, this works:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

class MyController
{

    /**
     * @Route("/example")
     * @Method("GET")
     */     
    public function exampleAction() {...}

}

But changing the namespaces to this fails:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\{
    Route, Method
}

I’m using Doctrine Annotations 1.2.7

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Yeah, we have to adapt, or throw an exception if a grouped use statement is detected (until we got a clean fix). A silent failure is not acceptable though.

The answer is: Do not use grouped annotation. They are not even a thing in the PHP world yet.

@kayladnls “solution” is how almost developers do it today.

It’s not a “solution” but couldn’t you easily do:

use Sensio\Bundle\FrameworkExtraBundle\Configuration as Config;

class MyController
{

    /**
     * @Config\Route("/example")
     * @Config\Method("GET")
     */     
    public function exampleAction() {...}

}

Nothing but I get a ping every time someone mentions it.

I submitted a pull request to fix this 3 months ago: https://github.com/doctrine/annotations/pull/69

@poldridge I left comments on https://github.com/doctrine/annotations/pull/69 Nothing wrong with the patch… it’s the language that is borked (PHP grammar is broken in consistency, as always) and both your patch and PHP language needs fix.

@lisachenko Just checked, and the PHP Annotations plugin supports it.

@lisachenko The newly released PHPStorm does allow for grouped use statements:

Support for group use statements

Enjoy full support for group use statements in PhpStorm, which includes:

Reuse of group use statements during auto-import Support of group uses during refactoring (move method, class, namespaces refactorings) Handy intentions to group or split use statements

From https://www.jetbrains.com/phpstorm/whatsnew/