我有一個非常具體的問題,我無法解決。PHP單程類生命週期破解
我有一個由多個類組成的PHP系統。它們大多數是泛型類,並使用自動加載處理程序加載,並在全局範圍內手動創建(新的運算符)。
但我也有一個主要的和非常重要的單例類,它也存在於全局範圍內並首先創建。我想讓它活到最後。這個類(首先創建)最後必須銷燬。
這個類是一個錯誤處理類,它只有兩個公共方法將被用於管理錯誤,捕獲異常,檢查口,發送報告等
但是,這個類將首先摧毀因爲它是第一個創建的。
是否有可能影響班級的生命並在所有其他班級死亡後使其死亡?
謝謝。
UPD 擴展碼樣本:
每個類中分離的文件中定義
class longlive { // error processing class
private function __construct() {}
public static function initialize() {
self::$instance = new longlive();
}
public function __destruct() {
/// check for runtime session errors, send reports to administrators
}
public static function handler($errno, $errstr, $errfile = '', $errline = '', $errcontext = array()) {
/// set_error_handler set this method
/// process errors and store
}
public static function checkExit() {
/// register_shutdown_function will register this method
/// will trigger on normal exit or if exception throwed
/// show nice screen of death if got an uncoverable error
}
}
class some_wrapper {
public function __construct() {}
public function __destruct() {}
}
class core {
private function __construct() {
$this->wrapper = new some_wrapper();
}
public static function initialize() {
self::$core = new core();
}
}
腳本體:
include_once('path/to/longlive.php');
longlive::initialize();
include_once('path/to/core.php');
core::initialize();
「安全原因「聽起來*非常不可能......我建議你看看依賴注入背後的概念:它們會讓你的代碼更容易,代碼更加靈活。 – lonesomeday 2012-02-08 18:56:53
Singleton的安全?真?! – KingCrunch 2012-02-08 19:23:08
你能否忘記關於未公開的安全原因並向我諮詢關於課程生命週期的問題?謝謝。 – ntvf 2012-02-08 19:24:51