뒤힛쌘--땍屢寧몸잚

2018-09-07 13:24

阅读:490

  +-------------------------------------------------------------------------------+
=굶匡槨Haohappy뗍<<CorePHPProgramming>>
=櫓ClassesandObjects寧覽돨궝션
=럇陋槨寮+몸훙懃돤
=槨긁출옵콘랙?骸캉뺑罔さ컫冗냘閏窕ぴ?剋剋
=뻑短툽팀寧攣,句寡뵨杰唐PHP갖봤諒묾谿쏵꼍!
=PHP5桔씩櫓懃:
+-------------------------------------------------------------------------------+
*/

뒤힛쌘--땍屢寧몸잚

뎠콱?荷桶뻗痔?콱矜狼죗놔뚤蹶壇唐돨杰唐긴좆뵨杰唐변鑒―굳냔槨橄昑뵨렘랬.3.1.1櫓鞫刻죄寧몸잚돨뭐냥.鬧雷瞳댕윅뵀({})코콱怜콘?荷貪幄옐畛揷鑒.3.1.2櫓鞫刻죄흔부瞳寧몸잚櫓땍屢힛몸橄昑뵨좃몸렘랬.

3.1.1

릿齡덜쯤 덜쯤흔苟:classNameextendsAnotherClass
{
AccessVariableDeclaration
AccessFunctionDeclaration
}



3.1.2

릿齡덜쯤 덜쯤흔苟:<?php
//땍屢寧몸뫄吏痰빵돨잚
classUser
{
//橄昑
public$name;
private$password,$lastLogin;

//렘랬
publicfunction__construct($name,$password)
{
$this->name=$name;
$this->password=$password;
$this->lastLogin=time();
$this->accesses++;
}

//삿혤離빈련狂돨珂쇌
functiongetLastLogin()
{
return(date(MdY,$this->lastLogin));
}
}

//눼쉔寧몸뚤蹶돨茄절
$user=newUser(Leon,sdf123);

//삿혤離빈련狂돨珂쇌
print($user->getLastLogin().<br>\n);

//댔丹痰빵츰
print($user->name<br>\n);
?>


뎠콱?荷澤轍?콱꼇矜狼寧츠鑒앴잚謹.긴좆옵콘角憐謹,俚륜눔샀諒角쥼寧몸뚤蹶,侶혤엄黨茄셥헙워.瞳?荷澤轍豚규梔當▧菰할뻗幟최桶?깃션?銶轍鍍캤б佯菰暄鳧蘚?

뎠콱?荷桶뻗値슘?콱杰隣돨뵨瞳잚棍꼬땍屢寧몸변鑒角寧湳돨.렘랬뵨橄昑떼唐몹菱돨츱츰왕쇌.侶雷瓘淪콱옵鹿갛홍뒈쉔접寧몸宅잚棍꼬변鑒谿츰돨렘랬,좃諒꼇삔녑敲.절흔,寧몸잚櫓옵鹿땍屢寧몸츰槨date()돨렘랬.뎃角콱꼇콘쉥寧몸렘랬츱츰槨PHP돨밑숩俚,흔for샀諒while.

잚렘랬옵콘관벵PHP櫓杰館돨typehint.Typehint角쥼寧몸눈뒵꽝鑒못렘랬돨잚돨츰俚.흔벎콱돨신굶딧痰렘랬깻눈뒵寧몸꼇角잚돨茄절돨긴좆,PHP쉥끓?爀뻗贅귤쩠?fatal)댄轎”.콱옵콘청唐못페劍잚謹못놔typehint,앎獗憐謹,俚륜눔,샀諒꼈랑令.瞳蝎畇돨珂빅,typehint角뤠壇뎠관벵鑒莉잚謹휄닸瞳轢累.

Typehint角꿎桿변鑒꽝鑒샀諒頓炬륜돨茄절돨鑒앴잚謹돨쌥쓺.콱옵콘悧角럿쀼侶몸렘랬.횅훰콱퓻齡횻寧몸꽝鑒극伎角컴蘆鑒앴잚謹,흔憐謹.3.2.1횅괏긍陋잚怜끓??idget돨茄절.

3.2.1

릿齡덜쯤 덜쯤흔苟:<?php
//莉숭
classWidget
{
public$name=none;
public$created=FALSE;
}

//陋토포
classAssembler
{
publicfunctionmake(Widget$w)
{
print(Making$w->name<br>\n);
$w->created=TRUE;
}
}

//쉔접寧몸莉숭뚤蹶
$thing=newWidget;
$thing->name=Gadget;

//陋토莉숭
Assembler::make($thing);
?>




뇜죄눈뒵꽝鑒돨긴좆棍,렘랬벵唐寧몸景喝돨긴좆.劍덜깊잚돨몸깎茄절.콱壇뎠痰侶몸윱寧蕨뚤蹶돨橄昑뵨페劍렘랬.寧硅충蕨뚤蹶돨刀喇솝?脘뻗厠뻠玖宙캇幄옻溯뻗澎쓸襪轍?뎃瞳PHP櫓렘랬돨훨부긴좆怜角瞳렘랬돨寧땍렀鍋코.鬧雷瞳User잚돨뭐芚변鑒櫓侶몸긴좆돨賈痰(3.1.2).

PHP瞳橄昑뵨렘랬?荷颱갤ⓕ諒뻗値촘幹牝ⓖ?흔public,private뵨protected.쥼棍,콱옵鹿痰”static”윱깃션寧몸냥逃.콱冷옵鹿瞳잚櫓?荷搭A?굶覽?牘齪騷勻뽕Х촘袈십슉켓仙亡鈴?

콱옵鹿瞳寧契櫓죗놔宮谿련狂렘駕돨섯몸橄昑,痰떵뵀윱롸몰劍쳬.瞳3.1.2櫓,User잚唐좃몸private橄昑--$password뵨$lastLogin.


评论


亲,登录后才可以留言!