php_task2

people.php

<?php
namespace MyProject;
class People
{
    private $name;
    private $age;
    private $height;
    private $weight;
    private $hobby;
    public static $currentNumber = 0;
    const MAXNUMBER = 2;
    /**
     * People constructor.
     * @param string $name
     * @param int $age
     */
    public function __construct(string $name, int $age, $height, $weight,  $hobby)
    {
        $this->name = $name;
        $this->age = $age;
        $this->height = $height;
        $this->weight= $weight;
        $this->hobby= $hobby;
        self::$currentNumber++ ;
        if( self::$currentNumber > self::MAXNUMBER )
        {
            echo "current people number " .self::$currentNumber."</br>\n";
            self::$currentNumber-- ;
            echo "construct failes        " ;
            echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp    ";
            $this->__destruct();
            return 1;
        }
        echo "current people number " .self::$currentNumber."</br>\n";
        echo "the person's name  is $this->name,</br> 
       the age is  $this->age years old,</br> 
       the height is  $this->height,</br>
       the weight is  $this->weight,</br>
       the hobby is </br>\n";
       var_dump($hobby);
       echo "</br>";
    }
    public function speak($action){
        echo "the method is $action  ";
    }
    public function eat(){
        $this->speak("eat");
        $this->weight=$this->weight+1;
        echo "current weight is ".$this->weight."</br>\n";
    }
    public function sleep(){
    $this->speak("sleep");
    $this->height=$this->height+1;
    echo "current height is ".$this->height."</br>\n";
    }
    public function run(){
        $this->speak("run");
        $this->weight=$this->weight-1;
        echo "current weight is ".$this->weight."</br>\n";
    }
    public function swim(){
        $this->speak("swim");
        $this->weight=$this->weight-1;
        echo "current weight is ".$this->weight."</br>\n";
    }
    public function haveBirthday(){
        $this->speak("haveBirthday");
        $this->age=$this->age+1;
        echo "current age is ".$this->age."</br>\n";
    }
    public function __destruct(){
        echo "destruct of " . __CLASS__ . " " . __METHOD__ . "</br>\n";
    }
}?>

?

main.php

<?php
require "people.php";
use MyProject\People;
$hooby = array(
    0=>"play basketball",
    1 => "play football",
);
$people = new People("ieso1",22,170,110,$hooby);
$people->haveBirthday();
$people->eat();
$people->sleep();
$people->swim();
$people->run();
echo "</br>\n";
$people1 = new People("ieso2",23,180,120,$hooby);
echo "</br>\n";
$people2 = new People("ieso3",24,185,130,$hooby);
?>

運(yùn)行結(jié)果

current people number 1
the person's name is ieso1,
the age is 22 years old,
the height is 170,
the weight is 110,
the hobby is
array(2) { [0]=> string(15) "play basketball" [1]=> string(13) "play football" }
the method is haveBirthday current age is 23
the method is eat current weight is 111
the method is sleep current height is 171
the method is swim current weight is 110
the method is run current weight is 109

current people number 2
the person's name is ieso2,
the age is 23 years old,
the height is 180,
the weight is 120,
the hobby is
array(2) { [0]=> string(15) "play basketball" [1]=> string(13) "play football" }

current people number 3
construct failes destruct of MyProject\People MyProject\People::__destruct
destruct of MyProject\People MyProject\People::__destruct
destruct of MyProject\People MyProject\People::__destruct
destruct of MyProject\People MyProject\People::__destruct

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市腐魂,隨后出現(xiàn)的幾起案子亭螟,更是在濱河造成了極大的恐慌,老刑警劉巖攒砖,帶你破解...
    沈念sama閱讀 211,376評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件作郭,死亡現(xiàn)場(chǎng)離奇詭異鲸匿,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)镊绪,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,126評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門匀伏,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人蝴韭,你說我怎么就攤上這事够颠。” “怎么了万皿?”我有些...
    開封第一講書人閱讀 156,966評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵摧找,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我牢硅,道長(zhǎng)蹬耘,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,432評(píng)論 1 283
  • 正文 為了忘掉前任减余,我火速辦了婚禮综苔,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己如筛,他們只是感情好堡牡,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,519評(píng)論 6 385
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著杨刨,像睡著了一般晤柄。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上妖胀,一...
    開封第一講書人閱讀 49,792評(píng)論 1 290
  • 那天芥颈,我揣著相機(jī)與錄音,去河邊找鬼赚抡。 笑死爬坑,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的涂臣。 我是一名探鬼主播盾计,決...
    沈念sama閱讀 38,933評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼赁遗!你這毒婦竟也來了署辉?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,701評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤吼和,失蹤者是張志新(化名)和其女友劉穎涨薪,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體炫乓,經(jīng)...
    沈念sama閱讀 44,143評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,488評(píng)論 2 327
  • 正文 我和宋清朗相戀三年献丑,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了末捣。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,626評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡创橄,死狀恐怖箩做,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情妥畏,我是刑警寧澤邦邦,帶...
    沈念sama閱讀 34,292評(píng)論 4 329
  • 正文 年R本政府宣布,位于F島的核電站醉蚁,受9級(jí)特大地震影響燃辖,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜网棍,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,896評(píng)論 3 313
  • 文/蒙蒙 一黔龟、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦氏身、人聲如沸巍棱。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,742評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)航徙。三九已至,卻和暖如春陷虎,著一層夾襖步出監(jiān)牢的瞬間到踏,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來泰國(guó)打工泻红, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留夭禽,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,324評(píng)論 2 360
  • 正文 我出身青樓谊路,卻偏偏與公主長(zhǎng)得像讹躯,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子缠劝,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,494評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,435評(píng)論 0 23
  • 藍(lán)是另一種藍(lán)閱讀 167評(píng)論 0 0
  • 光陰潮梯,請(qǐng)別用記憶 去裝扮離別 就像無法用落花 去拼湊燦爛的時(shí)節(jié) 于是我認(rèn)真的準(zhǔn)備告別 在每個(gè)可能離開的渡口 寫下相...
    暖洋洋的小蝸牛閱讀 202評(píng)論 0 2
  • 唐瓔曦秉馏,今年大二,被大家稱之為“預(yù)言仙女”脱羡。 只因那時(shí)我對(duì)一個(gè)年年考試掛科的大四學(xué)姐說了句:“你今年肯定不掛科萝究!”...
    瓔曦閱讀 229評(píng)論 0 1
  • 我總會(huì)羨慕別人的生活帆竹。穩(wěn)定的家庭,相愛的戀人脓规,蒸蒸日上的事業(yè)栽连,或是情同手足的朋友。在他困難時(shí)侨舆,會(huì)有人為他伸出援助之...
    進(jìn)擊的鹵蛋閱讀 102評(píng)論 0 0