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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -