Jump to content

Classes working together


FrOzeN

Recommended Posts

How can I get classes to work with one another? Possibly parse a pointer address through to use them?

Eg:
[b]index.php[/b]:
[code]include 'mysql.class.php';
include 'login.class.php';

$clsMySQL = &New MySQL_Wrapper;
$clsLogin = &New LoginClass;

$clsMySQL->db_host = "localhost";
// ....

$clsLogin->something();[/code]

Then in [b]login.class.php[/b]:
[code]class LoginClass{
    var $username;
    var $example;

    function test123() {
        // I want to be able to parse the ability of allowing ALL my classes access to use clsMySQL without redeclaring it eveywhere.
        // Eg:
        $sql_result = $clsMySQL->sql_query("SOMETHING ...");
        return $sql_result;
    }
}[/code]

By pointer address I mean is it possible to setup something like:
[b]index.php[/b]:
[code]include 'mysql.class.php';
include 'login.class.php';

$clsMySQL = &New MySQL_Wrapper;
$clsLogin = &New LoginClass;

$clsMySQL->db_host = "localhost";
$clsLogin->objMySQL = &clsMySQL; // Parse it's address?
// ....

$clsLogin->something();[/code]

[b]login.class.php[/b]:
[code]class LoginClass{
    var $username;
    var $example;
    var $objMySQL;

    function test123() {
        // I want to be able to parse the ability of allowing ALL my classes access to use clsMySQL without redeclaring it eveywhere.
        // Eg:
        $sql_result = $objMySQL->sql_query("SOMETHING ...");
        return $sql_result;
    }
}[/code]

Thanks. :)
Link to comment
https://forums.phpfreaks.com/topic/28519-classes-working-together/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.