PHPÀàʵÀý½Ì³Ì£¨Ê®Æߣ©£ºabstractÀàºÍabstract·½·¨
¿ÉÒÔʹÓÃabstractÀ´ÐÞÊÎÒ»¸öÀà»òÕß·½·¨¡£
ÓÃabstractÐÞÊεÄÀà±íʾÕâ¸öÀàÊÇÒ»¸ö³éÏóÀ࣬ÓÃabstractÐÞÊεķ½·¨±íʾÕâ¸ö·½·¨ÊÇÒ»¸ö³éÏó·½·¨¡£
³éÏóÀ಻Äܱ»ÊµÀý»¯¡£
³éÏó·½·¨ÊÇÖ»Óз½·¨ÉùÃ÷£¬¶øûÓз½·¨µÄʵÏÖÄÚÈÝ¡£
abstract ³éÏóÀà
¿ÉÒÔʹÓÃabstractÀ´ÐÞÊÎÒ»¸öÀà¡£
ÓÃabstractÐÞÊεÄÀà±íʾÕâ¸öÀàÊÇÒ»¸ö³éÏóÀà¡£
³éÏóÀ಻Äܱ»ÊµÀý»¯¡£
ÕâÊÇÒ»¸ö¼òµ¥³éÏóµÄ·½·¨£¬Èç¹ûËü±»Ö±½ÓʵÀý»¯£¬ÏµÍ³»á±¨´í¡£<?php
//¶¨ÒåÒ»¸ö³éÏóÀà
abstract class User
{
public function __toString() {
return get_class($this);
}
}
//ʵÀý»¯Õâ¸öÀà»á³öÏÖ´íÎó
echo new User();
?>
ÏÂÃæÀý× NormalUser ¼Ì³Ð×Ô UserÀ࣬¾Í¿ÉÒÔ±»ÊµÀý»¯ÁË¡£
<?php
//¶¨ÒåÒ»¸ö³éÏóÀà
abstract class User
{
public function __toString() {
return get_class($this);
}
}
//ʵÀý»¯Õâ¸öÀà»á³öÏÖ´íÎó
echo new User();
class NormalUser extends User
{
}
$a = new NormalUser();
echo "Õâ¸öÀà" . $a . "µÄʵÀý";
?>
µ¥¶ÀÉèÖÃÒ»¸ö³éÏóÀàÊÇûÓÐÒâÒåµÄ£¬Ö»ÓÐÓÐÁ˳éÏó·½·¨£¬³éÏóÀà²ÅÓÐÁËѪÈâ¡£ÏÂÃæ½éÉܳéÏó·½·¨¡£
abstract ³éÏó·½·¨
ÓÃabstractÐÞÊεÄÀà±íʾÕâ¸ö·½·¨ÊÇÒ»¸ö³éÏó·½·¨¡£
³éÏó·½·¨£¬Ö»Óз½·¨µÄÉùÃ÷²¿·Ö£¬Ã»Óз½·¨Ìå¡£
³éÏó·½·¨Ã»ÓÐ {} £¬¶ø²ÉÓà ; ½áÊø¡£
Ò»¸öÀàÖУ¬Ö»ÒªÓÐÒ»¸ö³éÏó·½·¨£¬Õâ¸öÀà±ØÐë±»ÉùÃ÷Ϊ³éÏóÀà¡£
³éÏó·½·¨ÔÚ×ÓÀàÖбØÐë±»ÖØд¡£
ÏÂÃæÊÇÒ»¸ö³éÏóÀ࣬ÆäÖÐÓÐÁ½¸ö³éÏó·½·¨£¬·Ö±ðÊÇ setSal() ºÍ getSal()¡£ÓÃÀ´È¡»Ø $sal Ô±¹¤µÄ¹¤×Ê¡£
<?php
abstract class User
{
protected $sal = 0;
//ÕâÀﶨÒåµÄ³éÏó·½·¨¡£
//×¢Òâ³éÏó·½·¨Ã»Óз½·¨Ì壬¶øÇÒ·½·¨½áÊøʹÓà ; ºÅ¡£
abstract function getSal();
abstract function setSal();
//¶¨ÒåËüµÄ__tostring·½·¨
public function __toString() {
return get_class($this);
}
}
?>
¼ÈÈ»UserÀ಻Äܱ»Ö±½Ó¼Ì³Ð£¬ÎÒÃÇдһ¸öNormalUserÀà¼Ì³Ð×ÔUserÀà¡£µ±ÎÒÃÇд³ÉÈçÏ´úÂëʱ£¬ÏµÍ³»á±¨´í¡£ Õâ¸ö´íÎó¸æËßÎÒÃÇ£¬ÔÚ UserÀàÖÐÓÐÁ½¸ö³éÏó·½·¨£¬ÎÒÃDZØÐëÔÚ×ÓÀàÖÐÖØдÕâÁ½¸ö·½·¨¡£
<?php
abstract class User
{
protected $sal = 0;
//ÕâÀﶨÒåµÄ³éÏó·½·¨¡£
//×¢Òâ³éÏó·½·¨Ã»Óз½·¨Ì壬¶øÇÒ·½·¨½áÊøʹÓà ; ºÅ¡£
abstract function getSal();
abstract function setSal();
//¶¨ÒåËüµÄ__tostring·½·¨
public function __toS
Ïà¹ØÎĵµ£º
ÎÒµÄgentooϵͳflashÎÞ·¨ÏÔʾÖÐÎÄ×ÖÌ壬¶øÇÒÎÞ·¨Ë¯Ãߺʹý»ú£¬Óй¦·òÔÙÑо¿Ò»ÏÂÈçºÎ½â¾ö°É
ÒòΪҪ¿ª·¢Ò»¸ö¸»Îı¾¹ýÂ˵ÄphpÀ©Õ¹£¬Òò´ËÑо¿ÁËÒ»ÏÂphpÀ©Õ¹µÄ¿ª·¢¼¼Êõ¡£
php.netÉϵÄÎĵµÐ´µÄ²»È«¡£»¹Òªµ½´¦ÕÒ¡£
¹ØÓÚ¸»Îı¾¹ýÂË£¬¾ÍÊÇ˵¸øÒ»¶Î»ìÔÓÁËhtml,js,cssµÄÎı¾£¬¹ýÂ˳ö°²È«µÄ²¿·Ö£¬Òò´ËÒª×öhtml,css½âÎö£¬ºÚ°×Ãûµ¥Éè¼Æ ......
Õâ¸öϵͳÆäʵÊÇÁ·Ï°php»ù±¾Óï·¨ºÍMySQLµÄ»ù±¾²éѯÓï¾ä¡£¸øÒ»ÆðѧϰµÄÅóÓÑ·ÖÏí¡£ ^_^
ÔÚphpÎļþÖУ¬Ë«Ð±¸ÜºóÃæÊÇ×¢ÊÍÓï¾ä£¬ÎÒÓÃÓ¢ÎÄдµÄ×¢ÊÍ¡£
Õû¸öϵͳËù°üº¬µÄ.htmºÍ.phpÎļþÓУº
add_que.htm——Ìí¼ÓÐÂÌâµÄÒ³Ãæ
insert.php——ÏÔʾÌí¼ÓÐÂÌâÐÅÏ¢µÄÒ³Ãæ
questionlist.php——ËùÓÐÎÊÌâÁÐ ......
¹¹Ôì·½·¨ÓÖ³ÆΪ¹¹Ô캯Êý£¬ÊǶÔÏó±»´´½¨Ê±×Ô¶¯µ÷Óõķ½·¨£¬ÓÃÀ´Íê³ÉÀà³õʼ»¯µÄ¹¤×÷¡£
¹¹Ô캯ÊýºÍÆäËüº¯ÊýÒ»Ñù£¬¿ÉÒÔ´«µÝ²ÎÊý£¬¿ÉÒÔÉ趨²ÎÊýĬÈÏÖµ¡£¹¹Ô캯Êý¿ÉÒÔµ÷ÓÃÊôÐÔ£¬¿ÉÒÔµ÷Ó÷½·¨¡£¹¹Ô캯Êý¿ÉÒÔ±»ÆäËü·½·¨ÏÔʽµ÷Óá£
ÔÚPHP4 ÖÐʹÓÃÓëÀàÃûͬÃûµÄ·½·¨Îª¹¹Ô캯Êý¡£ÔÚPHP5ÖÐÒÀȻ֧³ÖÁËÕâÖÖ·½Ê½£¬µ«²»½¨ÒéÔÙʹÓÃÕâÖÖ·½Ê½¡ ......
PHP5ÖÐʹÓÃparent::À´ÒýÓø¸ÀàµÄ·½·¨¡£ parent:: ¿ÉÓÃÓÚµ÷Óø¸ÀàÖж¨ÒåµÄ³ÉÔ±·½·¨¡£parent::µÄ×·Ëݲ»½öÓÚÖ±½Ó¸¸Àà¡£
ͨ¹ýparent::µ÷Óø¸Àà·½·¨
<!-- ÉùÃ÷Ò»¸öÔ±¹¤Àà,¾ÀíÀà¼Ì³Ð×ÔÔ±¹¤Àà -->
<?php
class employee
{
protected $sal = 3000;
public function getSal() {
$this->sal = $this-> ......
µ¥¼þģʽҪ½â¾öµÄÎÊÌâ¾ÍÊÇ“ÈçºÎÈÃÕâ¸öÀàÖ»ÓÐÒ»¸öʵÀý”¡£
ÎÒÃǵÄwebÓ¦ÓÃÖУ¬´óÁ¿Ê¹ÓÃÁËÊý¾Ý¿âÁ¬½Ó£¬Èç¹û·´¸´½¨Á¢ÓëÊý¾Ý¿âµÄÁ¬½Ó±ØÈ»ÏûºÄ¸ü¶àµÄϵͳ×ÊÔ´¡£
ÎÒÃÇÈçºÎ½â¾öÕâ¸öÎÊÌ⣬½¨Á¢Î¨Ò»µÄÊý¾Ý¿âÁ¬½ÓÊDZØÒªµÄ·½Ê½¡£
ÎÒÃÇÓÖÈçºÎÖªµÀÓëÕâ¸öÊý¾Ý¿âµÄÁ¬½ÓÊÇ·ñÒѾ½¨Á¢£¿ »¹ÊÇÐèÒªÏÖÔÚ½¨Á¢£¿
µ¥¼þģʽ¿ÉÒÔ½â¾öÕ ......