Answer the question
In order to leave comments, you need to log in
How to change the parent of a class in php?
How, besides code substitution, to replace the parent of the class / change the behavior of the class? What about the built-in class?
In my particular case - PDO, PDOStatement. I wrote a small wrapper that works conveniently with placeholders, I want to write tests, but I don’t understand how to do it at all.
The wrapper complements the existing methods, almost does not use its own. Of course, you can move your code into your methods, but this is at least an extra function call, and will be done only for the sake of testing.
github.com/hell0w0rd/dbal/tree/master/src/Fountain/Dbal
- here is
a link to the repository to talk in detail functions.
Answer the question
In order to leave comments, you need to log in
But what if you inherit not from the standard, but from your own, which in turn inherits the standard
class custom_PDOStatement extends \PDOStatement {}
Prefer composition over inheritance and you won't have these problems.
but this is at least an extra function call, and will be done only for the sake of testing
inheritance is not such a cheap procedure, or is everything ok?
$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('custom_PDOStatement', array($pdo)));
www.php.net/manual/en/function.runkit-class-adopt.php - isn't it?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question