Is there any overhead for using a PHP class object compared to a static class method?

I want to know if there is additional overhead for using an object in PHP instead of using a static method based on my examples below?

Sesseion from Session

$session = new Session;
$session->set(user_id, $uswer_id); //set session var
$session->get(user_id);            // get session var

VS


Static methods from the Session class

Session::set(user_id, $uswer_id); //set session var
Session::get(user_id);            // get session var
+3
source share
3 answers

There will be a bit of overhead because the object needs to be created and put into memory. But the question is whether it is noticeable.

My opinion is that you should look at what works most conveniently. Such optimization is mainly microoptimization.

+2
source

memory_get_usage(). , . , , . , , , , .

+5

OO . , , .

, . .

+1

Source: https://habr.com/ru/post/1729521/


All Articles