Skip to content

Instantly share code, notes, and snippets.

@devmsh
Created June 18, 2017 17:42
Show Gist options
  • Save devmsh/8be183f5dc8aa656c3809e17cb164ad2 to your computer and use it in GitHub Desktop.
Save devmsh/8be183f5dc8aa656c3809e17cb164ad2 to your computer and use it in GitHub Desktop.
simple IoC challenge
<?php
class B
{
}
class A
{
private $b;
function __construct(B $b)
{
$this->b = $b;
}
}
class Container
{
public static function make($className)
{
// TODO: enhance the make function code
return new $className();
}
}
$b = Container::make(B::class); // no problem
$a = Container::make(A::class); // Too few arguments exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment