PHP: How to cast object to inherited class?
- by andreyvlru
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?
}