OOP PHP - Returning $connection from functions (please see code)
<p>Procedural PHP works for me, but when I try to code like I do in objective C I cannot seem to get the functions to work. I think it has something to do with my variable scope and the functions not returning any values. Where am I going wrong with my code here?</p>

<pre><code>      &lt;?php 

      require_once("constants.php");

      class Main {

public $menu;
public $connection;

function connectToDatabase() {
    //connect to database &amp; check connection
    $connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
    if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " .      mysqli_connect_error(); }
}

function queryDatabase($select, $from) {
    $result = mysqli_query($connection,"SELECT $select FROM $from");
}

function closeDatabaseConnection() {
    mysqli_close($connection);
}

function displayMenu() {

    //connect to database &amp; check connection
    connectToDatabase();

    //get menu data
    queryDatabase(*, pages);

    //construct menu data
    echo '&lt;ul class="mainNavigation"&gt;';
    while($row = mysqli_fetch_array($result))
        {
            echo '&lt;li&gt;&lt;a href="' . $row['filename'] . '.php"&gt;';
            echo $row['menu_name'];
            echo '&lt;/a&gt;&lt;/li&gt;';
        }
    echo '&lt;/ul&gt;';

    //close connection
    closeDatabaseConnection();
}

function displayFooter() {

}

function getUser() {

}

function userLogIn() {

}

  } 
?&gt;
</code></pre>
