title: Global variable in php
body: <p>I have a class <code>userdb</code> in which I am declaring a function that returns the connection to the database:</p>
  
  <pre><code>return $con = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
  </code></pre>
  
  <p>I have various functions, even across other classes, where I have to access <code>$con</code> (e.g. to pass a query or to fetch data), but I can't access this variable.</p>
  
  <p>Is there a better way to define and use a database class? Remember that I have other classes where I need to access the <code>userdb</code> class.</p>