2
我想繼承PDOStatement類,並在我的網站腳本中使用它。PHP:如何將對象轉換爲繼承類?
但我很沮喪如何獲得所需的對象。 PDO ::查詢只返回直接PDOStatement對象,看起來像沒有其他方法來創建PDOStatement對象或繼承類。
起初我以爲PDOStatement對象對象移動到繼承類的構造函數 類似的東西:
$stmt = PDO -> query("select * from messages");
$messageCollection = new Messaging_Collection($stmt);
但如何讓PDOStatement對象的實例來繼承的對象(Messaging_Collection)。這對我來說是一個很大的問題。
class Messaging_Collection extends PDOStatement
{
public function __construct(PDOStatement $stmt)
{
//there i should to transform $stmt to $this
// direct $this = $stmt is not possible
// is there other right way?
}
這真的是我需要做的。我知道獲取物體的這種可能性,但這對我來說是新聞。 謝謝 – andreyvlru 2010-06-14 03:30:31