Hello here!

I'm a big fan of IoC too, and I think that PHP devs really need to have a
look into Inversion of control. Adding this feature to PHP can be useful for
providing a simple way to detect and manage the object creation process.

The "spl_factory_register" function allows to specify a manner to catch when
a "new" occurs, and to add an alternative way to manage the creation of
objects, by calling custom factories instead of using the built in "new"
process.

In fact, this method allow us to branch our objects managers (or dependency
injection containers) on classes that don't implement inversion of control
(like the widely used singleton pattern). This is huge ! However  it's
important to note that* this behavior can encourage some people to continue
writing hard coupled classes*, and use don't us or think about inversion of
control, letting the (service/object) container do the stuff for us. It can
be really *dangerous*, and maybe attack the problem by the wrong side ?

On a pragmatic point of view, *this is an actual need*, for sure. At least
Richard and me have encountered theses problems (and I think many other
people). This "spl_factory_register" would solve them in an elegant way.

About what Eloy Bote said, I think that traits and IoC are two different
concepts, both talking about code re-usability and good practices, and both
needed.

And, about the signature of the function itself, why not use a callback like
in "spl_autoload_register" function ?

Best regards
-- 
Alexis Métaireau
06 20 15 55 24 | 35 rue Léo Lagrange, 31400 Toulouse |
http://www.notmyidea.org

Reply via email to