Use a variable-object that was given as an argument
<p>I have some classes that sometimes should connect to the database during the same request. The solution I thought about was to give the PDO Object as an argument to the methods. There is a class that DB() that creates the connection and stores into a public attribute:</p>

<pre><code>class DB{
    public $conn;
    public function DB(){
        $this-&gt;conn = new PDO(...);//missed :S thxs!
    }
}

class Foo{
    public function Foo($db[, $more_possible_variables]){
        //implementing some stuff with $db
    }
}

/*index.php*/
require_once 'DB.php';
require_once 'Foo.php';

$db = new DB();
$foo = new Foo($db-&gt;conn);
/*End of index*/
</code></pre>

<p>I tried some ideas to make this work, but I always get the error that is not possible to handle a variable like an object. I have other solutions, but they are not recommended from an efficiency point of view...</p>
