2

I just started using composer and its autoloader for php. Then I added my own code to the autoloader using psr-0. Everything is fine except when I want to access the PDO (new PDO(...). It seems that its out of scope because the Autoloader expects it in my package (called MyAPP). The Error I am getting is:

PHP Fatal error: Class 'MyApp\PDO' not found in /var/www/ws/src/MyApp/WsDatenbank.php on line 15

My attempts to google ended up unsuccessful.
Please Help - Thanks in Advance

Langusten Gustel
  • 10,917
  • 9
  • 46
  • 59

1 Answers1

4

Posting my comment as the answer.

You have to do: new \PDO() (note the slash). When doing this you are loading the class for the global namespace. Otherwise it will be loaded from the current namespace (in your case MyApp).

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
  • Thanks, in PSR-4 goes like this: in class, `use \PDO;` In effect this is a root `\PDO` of namespaces. – vlad Sep 24 '15 at 00:18
  • I don't see how this is related to PSR4? :P – PeeHaa Sep 24 '15 at 07:25
  • Because we use composer as autoloading classmap, and I used root namespace for PDO. Work fine for now. When workig with OOP. More [why use composer PSR](http://stackoverflow.com/questions/22803419/why-use-a-psr-0-or-psr-4-autoload-in-composer-if-classmap-is-actually-faster) – vlad Sep 26 '15 at 11:47
  • 1
    - perhaps not the best solution - [link code](http://pastebin.com/CTCDfZW7) but one of solution – vlad Sep 26 '15 at 12:15