PHP对象实例化

class test {

	protected static $_instance = null;

	private $path = null;

	/**
	 * 实例化
	 */
	public static function getInstance() {

		if( !self::$_instance instanceof self ) {
			self::$_instance = new self;
		}

		return self::$_instance;
	}

	protected function  __construct() {
		
		$this->path = '/app/';
	}

	public function out() {

		echo $this->path;

	}

	// .....

}

test::getInstance()->out();
posted @ 2011-10-08 09:49  TobyDev  阅读(483)  评论(4编辑  收藏  举报