为什么我的变量不打印? PHP

时间:2017-07-02 01:59:49

标签: php

有谁能告诉我为什么我的角色统计数据不会被打印出来?我没有收到任何错误或语法消息..

这是我的第一个php项目。我无法弄清楚我错过了什么!

<?  
    class character{
        public $healthpoints = 100;
        public $isdead = false;
        public $class = "Mage";
        public $level = 10;
    }


    function checkdeath() {
    if($healthpoints >= 0){
        $isdead = true;
        }   
    }

    new character();

    function CharStats() {
        echo $healthpoints;
        echo $isdead;
        echo $class;
        echo $level;
    }

    CharStats;


    ?>

1 个答案:

答案 0 :(得分:2)

  

我无法弄清楚我错过了什么!

思考,所有

class Character{
    public $healthpoints = 100;
    public $isdead = false;
    public $class = "Mage";
    public $level = 10;

    function checkdeath() {
       if($this->healthpoints >= 0){
        $this->isdead = true;
      }   
    }

    function CharStats() {
        echo $this->healthpoints;
        echo $this->$isdead;
        echo $this->$class;
        echo $this->$level;
    }

}

$character = new Character();
$character->ChatStats();

再次阅读有关类/对象/等的内容。 - Classes and Objects in PHP