Hi,

First, I don't think this belongs in the PHP Manual (It has nothing to
do with PHP itself, and there are many resources about patterns out
there).

Second, if this goes in, the examples should be "done right". Right now
they look like more like PHP4 code then like PHP5 code.

For example, the singleton would look better like this:

class Test {
    static private $instance;
    
    private function __construct() 
    {    
    }
    
    static public function singleton() 
    {
        if (!isset(self::$instance)) {
            self::$instance = new Test;
        }
        return self::$instance;
    }
    
    public function bark()
    {
        print "Woof!\n";
    }
}

// This would fail, because the constructor is private:
// $test = new Test; 
// But this works:
$test = Test::singleton();
$test->bark();

Regards,
Stefan Walk

Reply via email to