Created
December 4, 2017 20:08
-
-
Save carousel/1236907f1232852ca926e27b034e7c40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Container | |
{ | |
public $bindings = []; | |
/** | |
* @param $key | |
* @param $value | |
*/ | |
public function __set($key, $value) | |
{ | |
$this->bindings[$key] = $value; | |
} | |
/** | |
* @param $key | |
* @return mixed | |
*/ | |
public function __get($key) | |
{ | |
return $this->bindings[$key](); | |
} | |
} | |
class Car | |
{ | |
public function __construct() | |
{ | |
echo get_class() . "\n"; | |
} | |
} | |
class Truck | |
{ | |
public function __construct() | |
{ | |
echo get_class() . "\n"; | |
} | |
} | |
$container = new Container; | |
$container->car = function(){ new Car;}; | |
$container->truck = function(){ new Truck;}; | |
$container->truck; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment