S
S
Spark1082018-03-06 10:20:25
PHP
Spark108, 2018-03-06 10:20:25

How to merge 2 classes into 1? Is it possible in principle?

There are let's say 2 classes, both from different namespaces (Although it doesn't matter), with 1 extending the other, but that's the question. The engine has its own implementation of class inheritance, and by the time the inheritance process starts, the required class has already been initialized. Inheritance cannot be done using standard PHP tools, since the class needs to be re-initialized.
In general, classes are allowed as follows:

<?php

namespace Test1;

class OneClass
{
    public function TestClass()
    {

    }
}

<?php

namespace Test2;

class TestClass
{
    public function twoMethod()
    {

    }
}

Actually, as I said earlier, the parent class is already initialized and has an impressive amount of data, and the extension method of the type ClassName extends ClassName will no longer work.
And then the question arose, is it possible to somehow extend the class or create a new one but combine them without losing the data of the main class, as well as replace / add methods that are in the extension, but not in the parent?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question