PHPÀàʵÀý½Ì³Ì£¨Ê®¶þ£©£ºÀàÖÐparent::¹Ø¼ü×Ö
PHP5ÖÐʹÓÃparent::À´ÒýÓø¸ÀàµÄ·½·¨¡£ parent:: ¿ÉÓÃÓÚµ÷Óø¸ÀàÖж¨ÒåµÄ³ÉÔ±·½·¨¡£parent::µÄ×·Ëݲ»½öÓÚÖ±½Ó¸¸Àà¡£
ͨ¹ýparent::µ÷Óø¸Àà·½·¨
<!-- ÉùÃ÷Ò»¸öÔ±¹¤Àà,¾ÀíÀà¼Ì³Ð×ÔÔ±¹¤Àà -->
<?php
class employee
{
protected $sal = 3000;
public function getSal() {
$this->sal = $this->sal + 1200;
return $this->sal ;
}
}
class Manager extends employee
{
//Èç¹ûÏëÈþÀíÔÚÔ±¹¤¹¤×ʵĻù´¡É϶෢1500Ôª
//±ØÐëÏȵ÷Óø¸ÀàµÄgetSal()·½·¨
public function getSal() {
parent::getSal(); // ÕâÀïµ÷ÓÃÁ˸¸ÀàµÄ·½·¨
$this->sal = $this->sal + 1500;
return $this->sal ;
}
}
$emp = new employee();
echo "ÆÕͨԱ¹¤µÄ¹¤×ÊÊÇ " . $emp->getSal();
echo "<br />";
$manager = new Manager();
echo "¾ÀíµÄ¹¤×ÊÊÇ: " . $manager->getSal();
?>
¸¸ÀàµÄprivateÊôÐÔ
PrivateÊôÐÔÊDz»Äܱ»¼Ì³ÐµÄ£¬Èç¹û¸¸ÀàÓÐ˽ÓеÄÊôÐÔ¡£ÄÇô¸¸ÀàµÄ·½·¨Ö»Îª¸¸ÀàµÄ˽ÓÐÊôÐÔ·þÎñ¡£
<?
class employee
{
private $sal = 3000;
//protected $sal = 3000;
public function getSal() {
return $this->sal;
}
}
class Manager extends employee
{
protected $sal = 5000;
public function getParentSal() {
//ÕâÀï·µ»ØµÄÊǸ¸ÀàµÄprivateÊôÐÔ
return parent::getSal();
}
}
$manager = new Manager();
echo "PHP " . phpversion() . "<br />";
echo $manager->getSal();
echo "<br />";
echo "parent's \$sal " . $manager->getParentSal();
?>
Èç¹û¸¸ÀàÖеÄÊôÐÔ±»×ÓÀàÖØдÁË¡£×¢Òâ µÚ5ÐеÄÊôÐÔ¶¨Òå±ä³Éprotected¡£ÄÇôÁ½´ÎµÄÊä³öÊDz»Ò»ÑùµÄ£¬Èç¹ûÄãѧ¹ýjava£¬Äã»á¾õµÃÕâÒ»Çж¼ÊǺÜÄÑÀí½âµÄ¡£ÔÚJavaÖе±×ÓÀà±»´´½¨Ê±£¬¸¸ÀàµÄÊôÐԺͷ½·¨ÔÚÄÚ´æÖж¼±»´´½¨£¬ÉõÖÁ¹¹Ô캯ÊýÒ²Òª±»µ÷Óá£PHP5²»ÊÇÕâÑù£¬PHP5µ÷Óø¸ÀàÓõÄÊÇparent:: ¶ø²»ÊÇ parent-> £¬Õâ×ãÒÔ˵Ã÷PHP5²»ÏëÔÚÄÚ´æÖÐÈø¸ÀàÒ²±»´´½¨¡£PHP5ÏëÈü̳бäµÄ±ÈJava¸ü¼òµ¥¡£ÊÊӦϾͺá£
Ïà¹ØÎĵµ£º
ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«Ñ§Ï°ÈçºÎͨ¹ýPHP 5µÄÒ»¸ö»ù±¾³éÏóÀàʹÓÃÍâ¼üÔ¼ÊøÀ´¸üÐÂÁ½¸öInnoDB±íµÄÊý¾Ý¡£ ÎÒÃǽ«Í¨¹ý¾ßÌåʾÀýÀ´ËµÃ÷ÈçºÎͨ¹ý·þÎñÆ÷¶Ë½Å±¾ÓïÑÔÀ´Ê¹ÓÃÍâ¼üÔ¼Êø¡£
¡¡¡¡Ò»¡¢ÀûÓÃÍâ¼üÔ¼Êø¸üÐÂMySQLÖеÄÊý¾Ý
¡¡¡¡ÏÖÔÚ£¬×îÁ÷ÐеĿªÔ´¹ØϵÐÍÊý¾Ý¿â¹ÜÀíϵͳ·ÇMySQLĪÊô£¬¶øMySQLÓÖÖ§³Ö¶à¸ö´æ´¢ÒýÇ棬ÆäÖÐĬÈϵÄÒ²ÊÇËٶȽϿìµÄ´ ......
Èç¹ûÀà³£Á¿ÄÜÍêÈ«ÌýÃüÓÚÎÒÃÇ(do our bidding)»¹ÊÇÏ൱²»´íµÄ£¬µ«ÊÇÆ䲻ѱ֮´¦»¹ÊÇÔçÔçµØ±©Â¶³öÀ´ÁË¡£Àà³£Á¿µÄÖµÖ»ÄÜÔÚ¶¨ÒåʱÉèÖ㬲¢ÇÒ²»ÄÜÔÚÀàµÄ·½·¨Öж¨Òå¡£³£Á¿Ö»Äܱ»³õÉè³ÉÆÕֵͨ(plain value)²»Äܱ»ÉèÖóɶÔÏó¡£ÉõÖÁÔÚ¶¨ÒåÀà³£Á¿Ê±£¬²»ÄÜʹÓÃ×Ö·ûÁ¬½Ó¡£
ÕýÈçÇ°ÃæÌáµ½µÄ£¬²»Äܸ ......
ÀÏÉù³¤Ì¸£¬×ÅÊÇÀ§»óºÜ¶àÈ˵ÄÎÊÌ⣬Èç¹û´¦Àí²»ºÃ£¬¶¼ÊÇÂÒÂ룬˵ÕâЩ»°²¢²»ÊÇÎÒ¶Ô±àÂëºÜ¾«Í¨£¬Ö»ÊÇÔÚÕâ·½ÃæÊǵÃÁôÉñ£¬×Ô¼º×ܽáÁËÒ»µãС¾Ñé(ÈÝÒ׳öÏÖÂÒÂëµÄµØ·½ÓÐphpÎļþÀïÃ棬Êý¾Ý¿âÀïÃ棬ҳÃæÏÔʾ):
1.ÔÚÓÚÊý¾Ý´ò½»µÀµÄʱºòmysql_query("set names 'utf-8'");
2.ÔÚ½¨Êý¾Ý¿âµÄʱºò£¬ÓÈÆäÊÇÓÃphpMyAdminÓëMYSQL´ò½»µÀʱºò£¬ ......
¼Ì³ÐÊÇÃæÏò¶ÔÏó×îÖØÒªµÄÌصãÖ®Ò»£¬¾ÍÊÇ¿ÉÒÔʵÏÖ¶ÔÀàµÄ¸´Óá£
ͨ¹ý“¼Ì³Ð”Ò»¸öÏÖÓеÄÀ࣬¿ÉÒÔʹÓÃÒѾ¶¨ÒåµÄÀàÖеķ½·¨ºÍÊôÐÔ¡£
¼Ì³Ð¶ø²úÉúµÄÀà½Ð×ö×ÓÀà¡£
±»¼Ì³ÐµÄÀ࣬½Ð×ö¸¸À࣬Ҳ±»³ÉΪ³¬Àà¡£
PHPÊǵ¥¼Ì³ÐµÄ£¬Ò»¸öÀàÖ»¿ÉÒԼ̳ÐÒ»¸ö¸¸À࣬µ«Ò»¸ö¸¸ÀàÈ´¿ÉÒÔ±»¶à¸ö×ÓÀàËù¼Ì³Ð¡£
´Ó×ÓÀàµÄ½Ç¶È¿´£¬Ëü“ ¼ ......