Answer the question
In order to leave comments, you need to log in
How to bypass the final constructor?
In general, I decided to slightly expand the standard SimpleXMLElement for my own needs, and I need to call the constructor of the parent class SimpleXMLElement when initializing the object.
But it wasn’t there: the constructor of the parent class turned out to be final, and it’s impossible to overload it with the constructor of the heir.
Question: how to bypass?
class MyClass extends SimpleXMLElement {
function __construct() {
parent::__construct('<data></data>');
}
}
PHP Fatal error: Cannot override final method SimpleXMLElement::__construct()
Answer the question
In order to leave comments, you need to log in
The first comment in the documentation already answers your question.
php.net/manual/ru/simplexmlelement.construct.php#79310
https://ru.wikipedia.org/wiki/Delegation_Pattern
class MyClass extends SimpleXMLElement {
function create_instance() {
$instance = new self('<data></data>');
...
return $instance;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question