<?php

//单例模式

class Singleton {

    private static $instance=null;

    private $value=null;

    private function __construct($value) {

        $this->value = $value;

    }

    public static function getInstance() {

        //echo self::$instance."<br/>";

        if ( self::$instance == null ) {

            echo "<br>new<br>";

            self::$instance = new Singleton("values");

        } else {

            echo "<br>old<br>";

        }

        return self::$instance;

    }

}

$x = Singleton::getInstance();

var_dump($x); // returns the new object

$y = Singleton::getInstance();

var_dump($y); // returns the existing object

?>