אתה יכול לעשות משהו כזה:
PHP קוד:
<?php
class app {
static public $db;
public static function init() {
//you can add here more functionality
self::$db = new DB();
self::$db->connect();
}
public static function getDb() {
return self::$db;
}
}
//page startup:
app::init();
//i want to use db inside a function:
function use_db() {
$db = app::getDb();
$db->query();
}
?>