I
I
Ivan Ivanov2019-06-21 13:51:31
PHP
Ivan Ivanov, 2019-06-21 13:51:31

Does the code run on inheritance?

Hello!
Recently, I just started hacking OOP, so a couple of small questions (the code is approximate everywhere):
the first piece

class a{
    function __consruct()
    {
        // тут запрос вида update
    }
}

second piece
class b extends a{
    # код
}

1. Will an update request from class a be executed when class b is called?
2. What is the difference between the code from the second piece and the code from the third piece, why is this done?
third piece
use a;
class b{
    # код
}

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Northern Lights, 2019-06-21
@php666

no database queries can be made in the constructor - let's start with this. the constructor is used to instantiate the class, if possible, there is no need to have any logic there at all (with the exception of passing parameters, for which separate set methods must also be implemented).
Any constructions in the constructor complicates debugging, makes the class opaque, difficult to maintain. All logic should be in methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question