0

With Symfony I'm taking the habit of using the class name resolver ::class (since php5.5):

use AppBundle\Entity\Product;

// ...

$resolver->setDefaults(array(
    'data_class' => Product::class
));

instead of the FQN string:

$resolver->setDefaults(array(
    'data_class' => 'AppBundle\Entity\Product'
));

I'm doing that for readability purpose and because it's handy to introscpect in some smart IDEs.

However, I'm seeing not so much examples of this practice in official docs. So I'm wondering if this is because of the compatibility concern (< php5.5) or because it would not be good to systematically import all the classes we need to reference.

My question is: Is it a good practice to use ::class everywhere we need to reference a FQN ?

4

1 回答 1

1

The answer seems to be:

Apart from the compatibility issue with php<5.5 there is nothing that would prevent one to use the ::class name resolver everywhere we need.

于 2016-06-08T06:58:27.043 回答