אחת מהשיטות לשתף אובייקטים בין כל הקוד שלך זו מחלקה שכל התוכן שלה(או רובו) סטטים.
אני אתן דוגמא למה שעשיתי באתר שלי(misron)
המערכת שלי רחוקה מלהיות מושלמת מבחינת התכנון שלה אבל אפשר ללמוד ממנה את העקרון.
PHP קוד:
class Misron {
static public $conf = array();
static public $browser = 'default';
static public $page_start_mtime;
static public $page_end_mtime;
static public $db;
}
Misron::$db = new DB();
//now i want to use the db within a function :
function myfunc() {
$res = Misron::$DB->query();
print_r($res->fetchAll());
}