We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

What is the difference between setShared and set?


$di->setShared('session', function () { $session = new SessionAdapter(); $session->start();

return $session;


$di->set('session', function () { $session = new SessionAdapter(); $session->start();

return $session;


All the codes are working. Is there any difference?


edited Nov '16

setShared always return same instantion of SessionAdapter

Shared services works as singletons.

Here you have explanation: https://docs.phalcon.io/pl/latest/reference/di.html#shared-services