1銆佷粈涔堟槸鍗曚緥妯″紡锛
浠庡悕瀛楀彲浠ョ悊瑙o紝纭繚鏌愪竴涓被鍙湁涓涓疄渚嬶紝鑰屼笖鑷瀹炰緥鍖栧苟鍚戞暣涓郴缁熸彁渚涜繖涓疄渚嬨傞氫織鐞嗚В(鍗曚緥妯″紡涓鑸篃灏辨槸寮鸿皟绫荤殑闈欐佽皟鐢,涓涓繘绋嬪涓涓被鐨勫娆¤皟鐢ㄥ彧浜х敓涓涓被瀵硅薄)
2銆佸崟渚嬫ā寮忔湁閭d簺濂藉鍛紵
PHP搴旂敤涓昏鐢ㄤ簬鏁版嵁搴撳簲鐢紝鍥犳浼氬瓨鍦ㄥぇ閲忕殑鏁版嵁搴撴搷浣滐紝浣跨敤鍗曚緥妯″紡鍙互閬垮厤澶ч噺鐨 new 鎿嶄綔娑堣楃殑璧勬簮銆
鍗曚緥妯″紡鏄竴绉嶅浜庡叏灞鍙橀噺鐨勬敼杩
3銆佸疄渚嬪満鏅細
<?php /*
* PHP鐢熸垚瀵硅薄涔嬭璁℃ā寮忊斿崟渚嬫ā寮
* 鐢ㄤ簬淇濆瓨鍩烘湰淇℃伅鐨勫崟渚嬬被 瀛樺偍URL鐩綍銆佹枃浠惰矾寰勭瓑鏁版嵁
* 1銆丳references瀵硅薄鍙互琚郴缁熶腑涓换浣曞璞′娇鐢
* 2銆丳references瀵硅薄涓嶈瀛樺偍鍦ㄤ細琚鍐欑殑鍏ㄥ眬鍙橀噺涓
*/ class Preferences{ private $props=array(); //淇濆瓨渚嬪疄渚嬪湪姝ゅ睘鎬т腑 private static $instance; //鏋勯犲嚱鏁板0鏄庝负private,闃叉鐩存帴鍒涘缓瀵硅薄 private function __construct(){} //鍗曚緥鏂规硶 public static function getInstance(){ if(empty(self::$instance)){ self::$instance=new Preferences(); } return self::$instance; } //璁剧疆灞炴у拰灞炴у public function setProperty($key,$val){ $this->props[$key]=$val; } //璇诲彇鍊 public function getProperty($key){ return $this->props[$key]; } } //寰楀埌Preferences绫荤殑鍗曚緥瀵硅薄 $pref=Preferences::getInstance(); //璁剧疆涓涓睘鎬 name 鐨勫 涓簃att $pref->setProperty("name","matt"); //绉婚櫎寮曠敤 unset($pref); //寰楀埌Preferences绫荤殑鍗曚緥瀵硅薄 $pref2=Preferences::getInstance(); //杈撳嚭灞炴ame 鐨勫睘鎬у 璇ュ睘鎬у兼湭涓㈠け print $pref2->getProperty("name");
浠ヤ笂灏辨槸PHP鐢熸垚瀵硅薄涔嬭璁℃ā寮忊斿崟渚嬫ā寮忕殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒