Reputation: 68470
I get this error when I try to use namespaces.
I have
namespace App;
the top, and the class looks like
class database{
function __construct(..)
try{
$this->db = new PDO(...) <-- here the error
...
}
}
I dont' understand how do namespaces work? Shouldn't PHP fallback to the default PDO class if app/PDO is not found?
Upvotes: 3
Views: 4384
Reputation:
Shouldn't PHP fallback to the default PDO class if app/PDO is not found?
No, it should not.
From the documentation:
Class names always resolve to the current namespace name. Thus to access internal or non-namespaced user classes, One must refer to them with their fully qualified Name
For your specific example, the fully qualified name for PDO
would be \PDO
.
Upvotes: 6