Well, $ con will already be an object, since it creates an instance of a new PDO object. If you are not trying to add functionality to your PDO, wrapping it is pointless.
However, the best way to share your userdb / PDO object (depending on whether you stick with the shell) with other objects is to use Injection Dependency . This is a fancy term for passing your db to any object. Since objects are passed by reference in PHP by default, if you first create your db object, all objects that receive it as an argument to the constructor / method will use the same single instance.
EDIT: Link to Dependency Injection Implementation
EDIT2: DI Explanation in Small Projects -
A normal DI pattern usually requires a special object called a DI container. This is a special object that automatically introduces a dependency in the object that it needs. For small projects, this is unnecessary. A simple version of DI with a low degree of complexity is simple:
class SomeClass { protected $db; public function __construct($db) { $this->db = $db; } } class SomeClass2 { public function SomeMethod($db) {
The magic is that since objects are passed by default link in PHP, $ obj and $ obj2 use the same db connection.
The whole idea is not to inflate the scope or encapsulation using the static method and to ensure that the classes and their methods are focused on what they need to work.
Singletones perform the exact opposite. They are accessed using static methods that bypass the scope, and since they are called and not passed, they never appear in the method signatures, so anyone who is not familiar with the code will not know about this hidden requirement. Even Erich Gamma, one of those who helped codify the Singleton template, regrets this :
I am for abandoning Singleton. Its use is almost always the smell of design.
In PHP, where there is no shared memory concept and where scripts are run once for each request, the only reason singleton should be used is easy access to one resource. Because objects are passed by reference, a single instance can be shared by several objects. From there, it's about good design and delegation.