'
'
'sasuke 'uchiha2020-08-03 05:11:41
PHP
'sasuke 'uchiha, 2020-08-03 05:11:41

What's the best way to do it with OOP?

There is a class in which work with sessions is going on, so here's how best to do it:

$class = new Class();
$sessionid = $class->getSession("auth_data");
$class->method($sessionid);

or like this:
$class = new Class("auth_data");
$class->method();

in the latter, the session itself is created when an instance of the class is created and stored internally, the fact is that in the first option, in 1 fork of the class, you can open several sessions and call the method with different sessions, and for 1 option, you need to fork the class again for each session for the method.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2020-08-03
@dgfsq23xzx

Your implementation is not very clear. Depending on the task, you can use either way.
You can also resort to using DI containers, and the issue of creating multiple sessions can be solved by a factory method or returning an object clone.

B
BATPYIIIKOB, 2020-08-03
@BATPYIIIKOB

For an example, check out the quality implementation:
pop-session

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question