Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carousel/1236907f1232852ca926e27b034e7c40 to your computer and use it in GitHub Desktop.
Save carousel/1236907f1232852ca926e27b034e7c40 to your computer and use it in GitHub Desktop.
<?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