PHP 5.3 namespaces & Symfony2

If you’re not used to namespaces, they can be easy to forget about. Essentially, if you’re going to use any class in your code, you need to ensure that the package or namespace it belongs to is imported at the top of your file, like so:

[php]
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller
{
public function indexAction()
{
return new Response("Hello");
}
}[/php]

If you don’t import the class Response, you’ll get a class not found error when you try to instantiate it.

Read more:

Leave a Reply

Your email address will not be published. Required fields are marked *