Omid
Omid

Reputation: 4715

PHP namespaces and inheritence

I want to extend standard PDO class. So i have:

namespace Example;

class NewPDO extends PDO {}

but i get the following error :

Fatal error: Class 'Example\PDO' not found in /home/hdocs/lab/index.php on line 4

I know that's because PDO class is not within Example namespace.
how can i solve that ?

Upvotes: 0

Views: 759

Answers (1)

xdazz
xdazz

Reputation: 160973

PDO is in global namespace, you should add \ before it.

namespace Example;

class NewPDO extends \PDO {}

Upvotes: 5

Related Questions