Skip to content

Instantly share code, notes, and snippets.

@alihammad-gist
Last active December 16, 2015 23:34
Show Gist options
  • Save alihammad-gist/75eb28fe3fdf61789898 to your computer and use it in GitHub Desktop.
Save alihammad-gist/75eb28fe3fdf61789898 to your computer and use it in GitHub Desktop.
<?php
$container['pdo'] = function ($C) {return new Pdo(..);}
$container['B'] = function ($c) {return new B($c['pdo']);} // pass in the dependency
$container['C'] = function ($c) {return new C($c['B']);}
class B {
function __construct(\PDO $a){}
}
class C {
function __construct(B $b){}
}
// i want to use class C
$c = $container['C'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment