>  Q&A  >  본문

为什么我name输不出来,求指教?

<?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");


我又来了我又来了2750일 전949

모든 응답(2)나는 대답할 것이다

  • 数据分析师

    数据分析师2017-10-01 00:48:56

    왜 이름을 입력할 수 없나요? 조언을 해주실 수 있나요? -PHP 중국어 사이트 Q&A-왜 이름을 입력할 수 없나요? 조언 부탁드립니다. -PHP 중국어 홈페이지 Q&A

    꼭 보고 배워보세요.

    회신하다
    0
  • 怪我咯

    怪我咯2017-03-13 17:38:20

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

    $this->name = $name;


    회신하다
    0
  • 취소회신하다