mowcixo
mowcixo

Reputation: 53

"use" php statement multiple?

Is there any way to make a "multiple use"?

I'm using an plugin in Silex to use ORM with it, and in each Entity I have to make a use like this:

use Doctrine\ORM\Mapping\Entity,
    Doctrine\ORM\Mapping\Table,
    Doctrine\ORM\Mapping\Id,
    Doctrine\ORM\Mapping\Column,
    Doctrine\ORM\Mapping\GeneratedValue,
    Doctrine\ORM\Mapping\ManyToOne,
    Doctrine\ORM\Mapping\ManyToOne;

So, my question is, is there in PHP a "multiple using" like Java? I mean:

use Doctrine\ORM\Mapping\*;

Or maybe using an autoload technique made by Silex/Symfony or something?

Upvotes: 5

Views: 243

Answers (2)

Alexander M. Turek
Alexander M. Turek

Reputation: 576

No, this is not possible – by design.

Imagine, you have two "wildcard" uses, like this:

use Foo\*;
use Bar\*;

Now, somewhere in your code, you would be accessing a class of one of those namespaces, like this:

$a = new Something();

Now, the class Something probably needs to be autoloaded, but to do so, php would need to resolve the full namespace path of your class: Foo\Something or Bar\Something? Or did we mean the class Something inside the current namespace?

Upvotes: 2

JamesHalsall
JamesHalsall

Reputation: 13485

Why not do this...

use Doctrine\ORM\Mapping as ORM;

Then in your annotations...

/**
 * @ORM\Column(type="int")
 */
 protected $name;

And so on...

Upvotes: 5

Related Questions