Php 名称空间的最佳实践:在Symfony上,使用(子)名称空间时性能的差异?
我正在构建一个API,我会问一些关于在Symfony2控制器上使用名称空间的问题。 这样做真的有区别吗Php 名称空间的最佳实践:在Symfony上,使用(子)名称空间时性能的差异?,php,symfony,namespaces,fosrestbundle,Php,Symfony,Namespaces,Fosrestbundle,我正在构建一个API,我会问一些关于在Symfony2控制器上使用名称空间的问题。 这样做真的有区别吗 <?php namespace My\APIBundle\Controller; use FOS\RestBundle\Controller\Annotations\View, FOS\RestBundle\Controller\Annotations\Post, FOS\RestBundle\Controller\Annotations\Get; use [...]
<?php
namespace My\APIBundle\Controller;
use FOS\RestBundle\Controller\Annotations\View,
FOS\RestBundle\Controller\Annotations\Post,
FOS\RestBundle\Controller\Annotations\Get;
use [...]
class MyRestController extends Controller {
[...]
/**
* @View()
* @Get()
*/
public function getAction(Thing $thing) {
return $thing;
}
/**
* @View()
* @Post()
*/
public function postAction() {
}
或做
<?php
namespace My\APIBundle\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use [...]
class MyRestController extends Controller {
[...]
/**
* @Rest\View()
* @Rest\Get()
*/
public function getAction(Thing $thing) {
return $thing;
}
/**
* @Rest\View()
* @Rest\Post()
*/
public function postAction() {
}
别名是否会加载给定命名空间中的所有内容,从而丢失性能?
或者它只加载注释类吗?第二个示例将加载注释目录下的所有类。Nope和Nope。类在需要时加载。如果向类加载器添加一些调试语句,您可以看到这一点。无论如何,任何性能差异都是无法测量的。