php di - PHP-DI - Differences between Factories and Objects -


php-di allows methods define injections, including factories , objects: http://php-di.org/doc/php-definitions.html.

factories:

testclass::class => function () {    return new testclass('param'); } 

the testclass instance created lazily, when needed.

objects:

testclass::class => di\object()->constructor('param') 

if use objects, instance created lazily?

if yes, what's difference between factories , objects?

php-di author here, seems there confusion (given question , how wrong other answer is). have improved documentation, clear things up: ec8120ee.

to answer questions:

if use objects, instance created lazily?

yes, definitions resolved lazily, object() too.

if yes, what's difference between factories , objects?

just syntax. in cases it's more practical write closure, in other cases may want avoid boilerplate using object().

it's syntax preference honestly.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -