<p>I am trying to code TDD style in PHP and one of my biggest stumbling blocks (other than lack of a decent IDE) is that I have to make my own hacked together IoC container just to inject all my mock objects properly.</p>

<p>Has anyone used an Ioc container in PHP?  All I've been able to find is <a href="http://www.phpclasses.org/browse/package/3382.html" rel="nofollow noreferrer">PHP IOC on the ever-annoying phpclasses.org</a> and it seems to have almost no documentation and not much of a following.</p>

[{'answer_id': 52203, 'author': 'crono', 'author_id': 1462, 'author_profile': 'https://Stackoverflow.com/users/1462', 'pm_score': 4, 'selected': True, 'text': '<p>I played with some DI Frameworks for PHP, but I haven\'t used one in production. Have some links:</p>\n\n<ol>\n<li><a href="http://www.stubbles.net" rel="noreferrer">http://www.stubbles.net/</a> which\nI think is the oldest I tried</li>\n<li><a href="http://php.xjconf.net/" rel="noreferrer">http://php.xjconf.net/</a></li>\n<li><a href="http://flow3.typo3.org/" rel="noreferrer">FLOW3</a> - I belive this one will\nbecome a very nice framework (its\nbeta right now)</li>\n</ol>\n\n<p>You mentioned you would use it for TDD - so maybe have a look at <a href="http://techblog.tilllate.com/2007/08/21/using-dependency-injection-for-unit-tests/" rel="noreferrer">Dependency Injection for Unit Tests in PHP</a></p>\n'}, {'answer_id': 402672, 'author': 'Beau Simensen', 'author_id': 50453, 'author_profile': 'https://Stackoverflow.com/users/50453', 'pm_score': 1, 'selected': False, 'text': '<p>I have been working on a <a href="http://substrate-php.org/" rel="nofollow noreferrer">PHP IoC/DI Container</a> named Substrate for the last six months. It is still very much a work in progress but it has been <a href="http://s3a.us/" rel="nofollow noreferrer">deployed in production</a> for a month and a half and has been working pretty well so far.</p>\n\n<p>Substrate is inspired by Spring Framework, but written with the strengths and limitations of PHP in mind. The documentation is pretty minimal at this point, but there is some <a href="http://code.google.com/p/substrate-php/wiki/SampleCode" rel="nofollow noreferrer">sample code</a>, including a unit testing example. Is this something that you think you might be able to use for TDD?</p>\n'}, {'answer_id': 410035, 'author': 'troelskn', 'author_id': 18180, 'author_profile': 'https://Stackoverflow.com/users/18180', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://phemto.sourceforge.net/" rel="nofollow noreferrer">Phemto</a> is being developed again, and looks quite promising IMHO.</p>\n\n<p>A few other similar projects, that you might want to look at:</p>\n\n<p><a href="http://github.com/troelskn/bucket" rel="nofollow noreferrer">bucket</a> (Disclaimer: I\'m the principal author of this one)</p>\n\n<p>The <a href="http://fisheye.codehaus.org/browse/picocontainer/php/picocontainer/trunk/container" rel="nofollow noreferrer">php-port of picocontainer</a>, has been around for a long time. I don\'t think it\'s being actively deveoped any more, but on the other hand, I believe that it\'s quite stable. It\'s been a long time since I looked at it though.</p>\n\n<p><del>A rather new project, I recently stumbled upon is <a href="http://phpcrafty.sourceforge.net/index.php" rel="nofollow noreferrer">Crafty</a>. Not sure how many people uses it though.</del></p>\n\n<p><del>I\'m also watching <a href="http://www.beberlei.de/sphicy/" rel="nofollow noreferrer">sphicy</a>, which looks interesting.</del></p>\n'}, {'answer_id': 5803372, 'author': 'marcelog', 'author_id': 727142, 'author_profile': 'https://Stackoverflow.com/users/727142', 'pm_score': 2, 'selected': False, 'text': '<p>You might also want to try Ding (http://marcelog.github.com/Ding) which is modeled after Spring(tm) for Java. It is a complete inversion of control and dependency injection container, which also supports AOP</p>\n'}, {'answer_id': 6873465, 'author': 'DrDol', 'author_id': 254234, 'author_profile': 'https://Stackoverflow.com/users/254234', 'pm_score': 2, 'selected': False, 'text': '<p>What about the <a href="http://components.symfony-project.org/dependency-injection/" rel="nofollow">Symfony Dependency Injection</a> or the PHP 5.3+ equivalent <a href="https://github.com/symfony/DependencyInjection" rel="nofollow">component</a> from the symfony 2.0 project.</p>\n'}, {'answer_id': 13340863, 'author': 'Matthieu Napoli', 'author_id': 245552, 'author_profile': 'https://Stackoverflow.com/users/245552', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://mnapoli.github.com/PHP-DI/" rel="nofollow">PHP-DI</a> is another dependency injection container.</p>\n\n<p>It features dependency injection through <strong>annotations</strong> and <strong>minimal configuration</strong>, here is an example:</p>\n\n<pre><code>class Foo {\n    /**\n     * @Inject\n     * @var Bar\n     */\n    private $bar;\n}\n</code></pre>\n\n<p>It\'s very easy to use, and it integrates with Zend Framework for example.</p>\n\n<p>(yes I do work on this framework)</p>\n'}, {'answer_id': 17469312, 'author': 'Apps 4 U', 'author_id': 1157480, 'author_profile': 'https://Stackoverflow.com/users/1157480', 'pm_score': 0, 'selected': False, 'text': '<p>Laravel 4 has the best IoC and DI framework. if you dont mind using a framework the Laravel 4 is the way to go</p>\n'}]
['https://Stackoverflow.com/questions/52072', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5056/']