mercredi 28 janvier 2015

PHP New class extend class instance

I have a class that extends PDO:



class MyPDO extends PDO {

}


Which has some helper methods such as insert() and update(). However, when used in addition to a framework, I would normally have access to an already initialised PDO instance.


How would I instantiate MyPDO so it extends the already existing PDO instance instead of creating a new one?



$pdo; # An already existing PDO connection.

$myPdo = new MyPDO(); # Creates a new PDO object

# I want to create a new MyPDO which extends $pdo

$myPdo = new MyPDO() + $pdo; # How would I accomplish this? Reflection?


I basically do not want to have more than one PDO connection but want the additional functionality of MyPDO. Can this be done? Maybe with Reflection?






Aucun commentaire:

Enregistrer un commentaire