2011-06-09 53 views

回答

7

它的工作原理就像一個構造函數?

它做到了,仍然沒有用於向後可計算,但正確的方式從PHP 5定義構造函數和以後是定義一個名爲__construct方法。

1

在< PHP5它作爲一個構造函數。在PHP5 +中,爲了向後兼容,它仍然以這種方式工作,但已被棄用。在PHP5 +中,您應該使用__construct()

1

這是你將如何在PHP4定義一個類的構造函數..但它仍然是有效的向後兼容性是過時和PHP5應該使用__construct()

試試這個讓你的類PHP4兼容, PHP5

class foo { 
//forward php4 to constructor 
function foo() { 

    return $this->__construct(); 
} 

//constructor php5 
function __construct() { 

    register_shutdown_function(array(&$this, "__destruct")); 
} 

}

相關問題