I
I
Ivan Ivanov2019-06-26 18:58:45
PHP
Ivan Ivanov, 2019-06-26 18:58:45

Should the constructor be executed as a shared functionality?

Hello!
In the Main class, for example, there is a login method, after submitting the form, validation-authorization occurs and a redirect back to Main::login, I check the authorization in the method itself and if it is logged in, then I redirect to another class - this works.
Question: if I put the authorization check in the constructor of the Main class, should it be executed?
Thank you.
ps because there are several methods in Main and each check is not camille and you need a general check for the whole class, I take out if the checks from the methods are one check to the constructor, then there is no redirect.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2019-06-26
@FanatPHP

There shouldn't be any Main class, at least with the Login method.

A
Adamos, 2019-06-26
@Adamos

The name Main by this very word involuntarily pushes you towards the Superclass antipattern.
If the class is busy with authorization, it is logical to call it Auth, and you will not have the desire to cram the rest of the engine into it.
"not camille" - not comme il faut. Comme il faut - "not comme il faut".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question