Alright I have a few classes and I'm wanting to pass on an initiated class object but I keep getting errors. It'll work one time, then other times I'll get a
PHP Fatal error: Cannot redeclare class
I don't know what I'm doing wrong. I'm basically trying to clean up my code because I'm ALWAYS having 2-3 includes for every one of my pages. I'd rather just include one class and pass on or use the other classes instances from there. Here's an example of what I have now:
Manage.php - Main Class
<?php
include_once('/path/to/DB.php');
class Manage {
public $db;
public function __construct() {
$this->db = new DB($host,$dbName,$user,$pass);
//other constructor stuff
}
//other functions
}
DB.php - Helper Class
<?php
class DB {
public $conn;
public function __construct($host = false, $db = false, $user = false, $pass = false) {
//connect to database
}
//functions for interacting with the database (get,query,update,insert, etc)
}
UseOfClass.php - Shows how I'd like to use it
<?php
include('/path/to/Manage.php');
$manage = new Manage();
$results = $manage->db->get('table_name');
print_r($results);