"Use" php short instruction?

Is there a way to do reusability?

I use a plugin in Silex to use ORM with it, and in every Entity I have to use it as follows:

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 "reuse" in PHP like Java? I mean:

use Doctrine\ORM\Mapping\*;

Or maybe use the autoload method created by Silex / Symfony or something like that?

+5
source share
2 answers

No, this is not possible - by design.

Imagine you have two “wildcards,” for example:

use Foo\*;
use Bar\*;

Now, somewhere in your code, you will be accessing a class of one of these namespaces, for example:

$a = new Something();

Something, , , php : Foo\Something Bar\Something? Something ?

+2

...

use Doctrine\ORM\Mapping as ORM;

...

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

...

+5

All Articles