为什么我name输不出来,求指教?
我又来了
我又来了 2017-03-13 17:37:58
0
2
944
<?php
date_default_timezone_get('PRC');
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/8/16
 * Time: 15:55
 */
class Human{
    public $name;
    public $height;
    public $weight;

    public function ect($food){
       echo $this->name."'s eating".$food;
    }
}
class NbaPlayer extends Human{
    public $team="bull";
    public $playerNumber="23";

    function __construct($name,$height,$weight,$team,$playerNumber){
        echo "构造函数调用成功";
    }
}
$jordan=new NbaPlayer("jordan","198cm","98kg","bull","23");
echo $jordan->name."\n";
$jordan->ect("Apple");


我又来了
我又来了

reply all(2)
数据分析师

Why can’t I type my name? Can you please give me some advice? -PHP Chinese website Q&A-Why can’t I type my name? Can you please give me some advice? -PHP Chinese website Q&A

Let’s take a look and learn.

刘奇

因为你的构造函数什么都没做,只是输出了"构造函数调用成功" ,你只是定义了 name 属性,你在构造函数中加上一句  

$this->name = $name;


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!