Quote Originally Posted by DougBTX
Well, while we are coding in PHP, we might a well code in PHP.

PHP Code:
<pre><?php

class FileLogger { function FileLogger $foo ) { } }
class 
Application { function run ( ) { echo '..running..'; } }

class 
Container {
    var 
$things = array();
    function &
get $something ) {
        if ( !isset(
$this->registry[$something]) ) {
            
$this->things[$something] = $something($this);
        }
        return 
$this->things[$something];
    }
}

function 
LogFile (&$c) { return "logfile.log"; }
function 
Logger (&$c) { return new FileLogger($c->get('LogFile')); }
function 
Application (&$c) {
    
$application = new Application;
    
$application->logger $c->get('Logger');
    return 
$application;
}

$c =& new Container;
$app =& $c->get('Application');
$app->run();

?></pre>
Even if it is as close a rip of the Ruby as I can get in a first try. I think PHP dulls the mind, and that Container should be a singleton. (In the Ruby version there is a ContainerRegistry, and it is the singleton. What's the code of the day for making singletons in PHP4/5 = PHP0.8 as I think I'll call it?)

Douglas
Very nice code. Thumbs up.