PHPÀàʵÀý½Ì³Ì£¨¶þÊ®£©£ºPHPÀà½Ó¿ÚµÄʵÏÖ½Ó¿Ú
ÀàʵÏÖ½Ó¿ÚҪʹÓà implements ¡£ÀàʵÏÖ½Ó¿ÚҪʵÏÖÆäÖеijéÏó·½·¨¡£Ò»¸öÀà¿ÉÒÔʵÏÖ¶à¸ö½Ó¿Ú¡£
Ò»¸öÀà¿ÉÒÔʹÓà implements ʵÏÖ½Ó¿Ú£¬ÉõÖÁ¿ÉÒÔʵÏÖ¶à¸ö½Ó¿Ú¡£
´ó²¿·ÖµÄÊé˵£¬ÕâÑùÊÇΪÁËʵÏÖPHPµÄ¶à¼Ì³Ð¡£ÎªÊ²Ã´ÄØ£¿
PHP5Êǵ¥¼Ì³ÐµÄ£¬Ò»¸öÀàÖ»¿ÉÒԼ̳Ð×ÔÒ»¸ö¸¸Àà¡£½Ó¿Ú¿ÉÒÔʵÏÖ¶à¸ö£¬ÕâÑù¾ÍÊǶà¼Ì³ÐÁË¡£
ÕâÑù˵ÓÐЩµÀÀí¡£µ«£¬¼ÈÈ»½Ó¿ÚÀïÃæµÄ·½·¨Ã»Óз½·¨Ì壬ËùνµÄ¶à¼Ì³ÐÓÖÓÐʲôÒâÒ壿
½Ó¿ÚµÄÒâÒåÔÚÓÚºóÃæÒ»½Ú¼ÌÐø˵µÄ¶à̬¡£
ʹÓÃimplementsʵÏÖ½Ó¿Ú
ʹÓÃimplementsÀ´ÊµÏÖÒ»¸ö½Ó¿Ú¡£Èç¹ûʵÏÖ½Ó¿Ú¶øûÓÐʵÏÖÆäÖеijéÏó·½·¨£¬»á±¨´íÈçÏ¡£
<?php
interface User
{
const MAX_GRADE = 99; //´Ë´¦²»ÓÃÉùÃ÷£¬¾ÍÊÇÒ»¸ö¾²Ì¬³£Á¿
function setName($name);
static function getName() {
}
}
class NoumalUser implements User
{
}
?>
Fatal error: Interface function User::getName() cannot contain body in C:\wamp\www\tt.php on line 5 ʵÏÖ½Ó¿ÚҪʵÏÖ·½·¨¡£×¢Ò⾲̬±äÁ¿µÄʹÓá£
<?php
interface User
{
const MAX_GRADE = 99; //´Ë´¦²»ÓÃÉùÃ÷£¬¾ÍÊÇÒ»¸ö¾²Ì¬³£Á¿
function setName($name);
function getName();
}
//ʵÏÖ½Ó¿Ú
class NoumalUser implements User
{
private $name;
function getName() {
return $this->name;
}
function setName($_name) {
$this->name = $_name;
}
}
$normalUser = new NoumalUser(); //´´½¨¶ÔÏó
$normalUser->setName("http://www.isstudy.com");
echo "URL is " . $normalUser->getName();
echo "<br />";
echo "MAX_GRADE is " . NoumalUser::MAX_GRADE; //¾²Ì¬³£Á¿
?>
ʵÏÖ¶à¸ö½Ó¿Ú
Ò»¸öÀà¿ÉÒÔʵÏÖ¶à¸ö½Ó¿Ú¡£Ö»ÒªÊ¹Óà , ºÅ½«¶à¸ö½Ó¿ÚÁ´½ÓÆðÀ´¾Í¿ÉÒÔ¡£
<?php
interface User
{
const MAX_GRADE = 99; //´Ë´¦²»ÓÃÉùÃ÷£¬¾ÍÊÇÒ»¸ö¾²Ì¬³£Á¿
function setName($name);
function getName();
}
interface administrator
{
function setBulletin($_bulletin) ;
}
//¶à¸ö½Ó¿Ú
class NoumalUser implements User, administrator
{
private $name;
function getName(){ }
function setName($_name) {}
function setBulletin($_setBulletin) {
}
}
?>
¼Ì³Ð²¢ÊµÏÖ½Ó¿Ú
<?php
class Student
{
protected $grade;
public function getGrade() {
return $this->grade;
}
Ïà¹ØÎĵµ£º
<?php
/*
Singleton && Registry Design Pattern Implementation
*/
class Registry {
private $_store = array();
public function getInstance() {
static $instance = array();
if (!$instance) {
$instance[0] = new ......
ÀÏÉù³¤Ì¸£¬×ÅÊÇÀ§»óºÜ¶àÈ˵ÄÎÊÌ⣬Èç¹û´¦Àí²»ºÃ£¬¶¼ÊÇÂÒÂ룬˵ÕâЩ»°²¢²»ÊÇÎÒ¶Ô±àÂëºÜ¾«Í¨£¬Ö»ÊÇÔÚÕâ·½ÃæÊǵÃÁôÉñ£¬×Ô¼º×ܽáÁËÒ»µãС¾Ñé(ÈÝÒ׳öÏÖÂÒÂëµÄµØ·½ÓÐphpÎļþÀïÃ棬Êý¾Ý¿âÀïÃ棬ҳÃæÏÔʾ):
1.ÔÚÓÚÊý¾Ý´ò½»µÀµÄʱºòmysql_query("set names 'utf-8'");
2.ÔÚ½¨Êý¾Ý¿âµÄʱºò£¬ÓÈÆäÊÇÓÃphpMyAdminÓëMYSQL´ò½»µÀʱºò£¬ ......
¼Ì³ÐÊÇÃæÏò¶ÔÏó×îÖØÒªµÄÌصãÖ®Ò»£¬¾ÍÊÇ¿ÉÒÔʵÏÖ¶ÔÀàµÄ¸´Óá£
ͨ¹ý“¼Ì³Ð”Ò»¸öÏÖÓеÄÀ࣬¿ÉÒÔʹÓÃÒѾ¶¨ÒåµÄÀàÖеķ½·¨ºÍÊôÐÔ¡£
¼Ì³Ð¶ø²úÉúµÄÀà½Ð×ö×ÓÀà¡£
±»¼Ì³ÐµÄÀ࣬½Ð×ö¸¸À࣬Ҳ±»³ÉΪ³¬Àà¡£
PHPÊǵ¥¼Ì³ÐµÄ£¬Ò»¸öÀàÖ»¿ÉÒԼ̳ÐÒ»¸ö¸¸À࣬µ«Ò»¸ö¸¸ÀàÈ´¿ÉÒÔ±»¶à¸ö×ÓÀàËù¼Ì³Ð¡£
´Ó×ÓÀàµÄ½Ç¶È¿´£¬Ëü“ ¼ ......
PHP5ÖÐʹÓÃparent::À´ÒýÓø¸ÀàµÄ·½·¨¡£ parent:: ¿ÉÓÃÓÚµ÷Óø¸ÀàÖж¨ÒåµÄ³ÉÔ±·½·¨¡£parent::µÄ×·Ëݲ»½öÓÚÖ±½Ó¸¸Àà¡£
ͨ¹ýparent::µ÷Óø¸Àà·½·¨
<!-- ÉùÃ÷Ò»¸öÔ±¹¤Àà,¾ÀíÀà¼Ì³Ð×ÔÔ±¹¤Àà -->
<?php
class employee
{
protected $sal = 3000;
public function getSal() {
$this->sal = $this-> ......
static¹Ø¼ü×ÖÓÃÀ´ÐÞÊÎÊôÐÔ¡¢·½·¨£¬³ÆÕâЩÊôÐÔ¡¢·½·¨Îª¾²Ì¬ÊôÐÔ¡¢¾²Ì¬·½·¨¡£
static¹Ø¼ü×ÖÉùÃ÷Ò»¸öÊôÐÔ»ò·½·¨ÊǺÍÀàÏà¹ØµÄ£¬¶ø²»ÊǺÍÀàµÄij¸öÌض¨µÄʵÀýÏà¹Ø£¬Òò´Ë£¬ÕâÀàÊôÐÔ»ò·½·¨Ò²³ÆΪ“ÀàÊôÐÔ”»ò“Àà·½·¨”
Èç¹û·ÃÎÊ¿ØÖÆȨÏÞÔÊÐí£¬¿É²»±Ø´´½¨¸ÃÀà¶ÔÏó¶øÖ±½ÓʹÓÃÀàÃû¼ÓÁ½¸öðºÅ“::”µ÷ ......