PHP V5ǨÒÆÖ¸ÄÏ
×÷Õß ØýÃû¼¼Êõ
À´Ô´ NET±à³Ì
ä¯ÀÀ
·¢²¼Ê±¼ä 2012-05-22
items ³ÉÔ±±äÁ¿¡£Õâ´Î¸Ä¶¯ÈçÏÂËùʾ¡£
Çåµ¥ 3. access2.php5
<?php
class Configuration
{
¡¡private
PHP V5ǨÒÆÖ¸ÄÏ - ÁèÖڿƼ¼
¿ìËÙÒµÎñͨµÀ
PHP V5ǨÒÆÖ¸ÄÏ
×÷Õß ØýÃû¼¼Êõ
À´Ô´ NET±à³Ì
ä¯ÀÀ
·¢²¼Ê±¼ä 2012-05-22
|
content |
ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn
ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!
|
|
|
items = array();
¡¡public function __construct() {
¡¡¡¡$this->_items[ ''imgpath'' ] = ''images'';
¡¡}
¡¡public function get( $key ) {
¡¡¡¡return $this->_items[ $key ];
¡¡}
}
$c = new Configuration();
echo( $c->get( ''imgpath'' )."\n" );
?>
Èç¹ûÕâ¸ö¶ÔÏóµÄʹÓÃÕ߶¼ÒªÖ±½Ó·ÃÎÊÏîÕóÁУ¬·ÃÎʽ«±»¾Ü¾ø£¬ÒòΪ¸ÃÕóÁб»±ê¼ÇΪ private¡£ÐÒÔ˵ÄÊÇ£¬Ê¹ÓÃÕß·¢ÏÖ get() ·½·¨¿ÉÒÔÌṩ¹ãÊÜ»¶ÓµÄ¶ÁȡȨÏÞ¡£
ΪÁË˵Ã÷ÈçºÎʹÓà protected ȨÏÞ£¬ÎÒÐèÒªÁíÒ»¸öÀ࣬¸ÃÀà±ØÐë¼Ì³Ð×Ô Configuration Àà¡£ÎÒ°ÑÄǸöÀà³ÆΪ DBConfiguration£¬²¢¼Ù¶¨¸ÃÀཫ´ÓÊý¾Ý¿âÖжÁÈ¡ÅäÖÃÖµ¡£´ËÉèÖÃÈçÏÂËùʾ¡£
Çåµ¥ 4. access3.php
<?php
class Configuration
{
¡¡protected
PHP V5ǨÒÆÖ¸ÄÏ - ÁèÖڿƼ¼
¿ìËÙÒµÎñͨµÀ
PHP V5ǨÒÆÖ¸ÄÏ
×÷Õß ØýÃû¼¼Êõ
À´Ô´ NET±à³Ì
ä¯ÀÀ
·¢²¼Ê±¼ä 2012-05-22
|
content |
ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn
ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!
|
|
|
items = array();
¡¡public function __construct() {
¡¡¡¡$this->load();
¡¡}
¡¡protected function load() { }
¡¡public function get( $key ) {
¡¡¡¡return $this->_items[ $key ];
¡¡}
}
class DBConfiguration extends Configuration
{
¡¡protected function load() {
¡¡¡¡$this->_items[ ''imgpath'' ] = ''images'';
¡¡}
}
$c = new DBConfiguration();
echo( $c->get( ''imgpath'' )."\n" );
?>
ÕâÕÅÇåµ¥ÏÔʾÁË protected ¹Ø¼ü×ÖµÄÕýÈ·Ó÷¨¡£»ùÀඨÒåÁËÃûΪ load() µÄ·½·¨¡£´ËÀàµÄ×ÓÀཫ¸²¸Ç load() ·½·¨°ÑÊý¾ÝÌí¼Óµ½ items ±íÖС£load() ·½·¨¶ÔÀ༰Æä×ÓÀàÊÇÄÚ²¿·½·¨£¬Òò´Ë¸Ã·½·¨¶ÔËùÓÐÍⲿʹÓÃÕ߶¼²»¿É¼û¡£Èç¹û¹Ø¼ü×Ö¶¼ÊÇ private µÄ£¬Ôò load() ·½·¨²»Äܱ»¸²¸Ç¡£
ÎÒ²¢²»Ê®·Öϲ»¶´ËÉè¼Æ£¬µ«ÊÇ£¬ÓÉÓÚ±ØÐëÈà DBConfiguration ÀàÄܹ»·ÃÎÊÏîÕóÁжøÑ¡ÓÃÁË´ËÉè¼Æ¡£ÎÒÏ£Íû¼ÌÐøÓÉ Configuration ÀàÀ´Íêȫά»¤ÏîÕóÁУ¬ÒÔ±ãÔÚÌí¼ÓÆäËû×ÓÀàºó£¬ÄÇЩÀཫ²»ÐèÒªÖªµÀÈçºÎά»¤ÏîÕóÁС£ÎÒ×öÁËÒÔϸü¸Ä¡£
Çåµ¥ 5. access4.php5
<?php
class Configuration
{
¡¡private
PHP V5ǨÒÆÖ¸ÄÏ - ÁèÖڿƼ¼
¿ìËÙÒµÎñͨµÀ
PHP V5ǨÒÆÖ¸ÄÏ
×÷Õß ØýÃû¼¼Êõ
À´Ô´ NET±à³Ì
ä¯ÀÀ
·¢²¼Ê±¼ä 2012-05-22
|
content |
ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn
ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!
|
|
|
items = array();
¡¡public function __construct() {
¡¡¡¡$this->load();
¡¡}
¡¡protected function load() { }
¡¡protected function add( $key, $value ) {
¡¡¡¡$this->_items[ $key ] = $value;
¡¡}
¡¡public function get( $key ) {
¡¡¡¡return $this->_items[ $key ];
¡¡}
}
class DBConfiguration extends Configuration
{
¡¡protected function load() {
¡¡¡¡$this->add( ''imgpath'', ''images'' );
¡¡}
}
$c = new DBConfiguration();
echo( $c->get( ''imgpath'' )."\n" );
?>
ÏÖÔÚ£¬ÏîÕóÁпÉÒÔÊÇ private µÄ£¬ÒòΪ×ÓÀàʹÓÃÊܱ£»¤µÄ add() ·½·¨½«ÅäÖÃÏîÌí¼Óµ½ÁбíÖС£Configuration Àà¿ÉÒÔ¸ü¸Ä´æ´¢ºÍ¶ÁÈ¡ÅäÖÃÏîµÄ·½·¨¶ø²»ÐèÒª¿¼ÂÇËüµÄ×ÓÀà¡£Ö»Òª load() ºÍ add() ·½·¨ÒÔͬÑùµÄ·½·¨ÔËÐУ¬×ÓÀà¾ÍÓ¦µ±²»»á³öÎÊÌâ¡£
¶ÔÓÚÎÒÀ´Ëµ£¬Ôö¼ÓÁË·ÃÎÊ¿ØÖÆÊÇ¿¼ÂÇÒÆÖÁ PHP V5 µÄÖ÷ÒªÔÒò¡£ÄѵÀ¾ÍÒòΪ Grady Booch ˵ PHP V5 ÊÇËÄ´óÃæÏò¶ÔÏóµÄÓïÑÔ֮һô£¿²»£¬ÒòΪÎÒÔø¾½ÓÊÜÁËÒ»¸öÈÎÎñÀ´Î¬»¤ 100KLOC C++ ´úÂ룬ÔÚÕâЩ´úÂëÖÐËùÓз½·¨ºÍ³ÉÔ±¶¼±»¶¨ÒåΪ public µÄ¡£ÎÒ»¨ÁËÈýÌìʱ¼äÀ´Çå³ýÕâЩ¶¨Ò壬²¢ÔÚÇå³ý¹ý³ÌÖУ¬Ã÷ÏԵؼõÉÙÁË´íÎóÊý²¢Ìá¸ßÁË¿Éά»¤ÐÔ¡£ÎªÊ²Ã´£¿ÒòΪûÓзÃÎÊ¿ØÖÆ£¬¾Í²»¿ÉÄÜÖªµÀ¶ÔÏóÔõÑùʹÓÃÆäËû¶ÔÏó£¬Ò²¾Í²»¿ÉÄÜÔÚ²»ÖªµÀҪͻÆÆʲôÄѹصÄÇé¿öÏÂ×öÈκθü¸Ä¡£Ê¹Óà C++£¬ÖÁÉÙÎÒ»¹ÓбàÒë³ÌÐò¿ÉÓá£PHP ûÓÐÅ䱸±àÒë³ÌÐò£¬Òò´ËÕâÀà·ÃÎÊ¿ØÖƱäµÃÓú¼ÓÖØÒª¡£
ÆõÔ¼±à³Ì
´Ó PHP V4 ǨÒƵ½ PHP V5 ʱ |