PHP: How to cast object to inherited class?

Posted by andreyvlru on Stack Overflow See other posts from Stack Overflow or by andreyvlru
Published on 2010-06-14T01:22:54Z Indexed on 2010/06/14 1:32 UTC
Read the original article Hit count: 412

Filed under:
|
|
|

I'd like to inherit PDOStatement class and use it in my website scripts.

But I am frustrated how to get required object. PDO::query returns only direct PDOStatement object and looks like there are no other method to create PDOStatement object or inherited class.

Initially i thought to move PDOStatement object to constructor of inherit class Something like that:

$stmt = PDO -> query("select * from messages");
$messageCollection = new Messaging_Collection($stmt);

But how to make instance of PDOStatement to inherited object (Messaging_Collection). It is a big question for me.

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?
}

© Stack Overflow or respective owner

Related posts about php

Related posts about oop