我在單例類中有一個方法,這個類是從父類中調用的,該類由子類擴展。調用兩次來自不同類的方法導致內存不足錯誤
假設我的類已被正確聲明和創建,這只是我的編碼邏輯的快速運行。
class Singleton
{
public function load_sys()
{
$this->something();
}
public function something()
{
$this->load();
}
public function load(){}
}
class Parent
{
public function __construct()
{
$this->sys = Singleton::init();
$this->sys->load_sys();
}
}
class Child extends Parent
{
public function __construct()
{
parent::__construct();
}
}
當我做這個,我得到這個錯誤:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4296 bytes) in ~~~.php on line 102
可能會造成什麼呢?
你應該寫你正在使用的PHP版本,以及你的操作系統。這對於OOP尤其重要。這些對於有效的錯誤報告是強制性的。這裏是當我嘗試在CLI,PHP 5.4.0中運行你的代碼時得到的結果:'PHP Parse error:syntax error,unexpected'(',expect'''in'/home/xxx/oop.php on line 2' – 2012-04-08 07:30:16
上面的代碼是不可行的代碼,它顯示事件的佈局順序 – Eli 2012-04-08 08:07:44